您只需要使用即可,
path_match而不必
match在模式引用整个字段路径时使用它,否则仅考虑其名称(最后一部分)。查看根对象的参考页,其中还包含一些与动态模板有关的文档。
您可能还想使用,
match_mapping_type因为您无法
"index":"analyzed"为例如数字或布尔字段设置。在这种情况下,您可能想根据字段类型做不同的事情。
我注意到您的文档包含产品根对象,您实际上并不需要它。我将其删除,因为类型名称已经是产品。
另外,除非真正需要,否则我将避免显式存储字段,例如,对于Elasticsearch而言,默认情况下会存储字段,这就是您一直需要的
_source字段。
以下映射应适用于您的情况(文档中没有产品根对象):
{ "product" : { "dynamic_templates": [ { "nested_feature": { "match" : "feature_*", "mapping" : { "type" : "nested" } } }, { "nested_template": {"path_match": "feature_*.*","match_mapping_type" : "string","mapping": { "type": "multi_field", "fields": { "{name}": { "type": "{dynamic_type}", "index": "analyzed" }, "facet": { "type": "{dynamic_type}", "index": "not_analyzed" } }} } } ] } }


