简体   繁体   English

在 elasticsearch 中定义动态映射索引字段的最佳方法

[英]Best way to define dynamic mapping index fields in elasticsearch

I have some couple of objects which contains dynamic keys.我有一些包含动态键的对象。 How can i define the mappings so that the search query gets optimised.我如何定义映射以便优化搜索查询。

eg I have following nested and object type fields例如,我有以下嵌套和 object 类型字段

"similarities": [
  {
    "key1": "value1",
    "key2": "value2"
  },
  {
    "key3": "value1",
    "key4": "value2"
  }
]
"entity": {
  "version": "SO",
  "Non-Commerical": "GGP"
}

For result, i need all documents where entity contains GGP no matter what the key is.对于结果,我需要entity包含GGP的所有文档,无论密钥是什么。 Can you help in defining the mappings and search query?您能帮忙定义映射和搜索查询吗?

You can use dynamic mapping for entity.* with copy_to to another field, let's say entity_values .您可以将entity.*动态映射copy_to一起使用到另一个字段,比如说entity_values Then you just need a match query against entity_values which now contains all of the values.然后,您只需要对entity_values进行match查询,该查询现在包含所有值。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM