我正在尝试按照> Elasticsearch在不同密钥,但是描述的解决方案不再起作用。
I'm trying to aggregate over field names in ES 5 as described in Elasticsearch aggregation on distinct keys But the solution described there is not working anymore.
我的目标是获取所有文档中的密钥。
My goal is to get the keys across all the documents. Mapping is the default one.
数据:
PUT products/product/1 { "param": { "field1": "data", "field2": "data2" } }查询:
GET _search { "aggs": { "params": { "terms": { "field": "_field_names", "include" : "param.*", "size": 0 } } } }我遇到以下错误:类型[[]的字段[_field_names]不支持Fielddata _field_names]
推荐答案环顾四周,似乎是ES> 5.X中唯一的获取方法唯一字段名称是通过映射端点完成的,并且由于无法在 _field_names 上进行汇总,因此您可能需要稍稍更改数据格式,因为映射端点会返回每个字段,无论嵌套如何。
After looking around it seems the only way in ES > 5.X to get the unique field names is through the mappings endpoint, and since cannot aggregate on the _field_names you may need to slightly change your data format since the mapping endpoint will return every field regardless of nesting.
我个人的问题是获取各种子/父文档的唯一键。
My personal problem was getting unique keys for various child/parent documents.
我发现您是否在按映射端点时以 prefix.field 格式添加字段名称前缀。
I found if you are prefixing your field names in the format prefix.field when hitting the mapping endpoint it will automatically nest the information for you.
PUT products/product/1 { "param.field1": "data", "param.field2": "data2", "other.field3": "data3" } GET products/product/_mapping { "products": { "mappings": { "product": { "properties": { "other": { "properties": { "field3": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } } } }, "param": { "properties": { "field1": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } }, "field2": { "type": "text", "fields": { "keyword": { "type": "keyword", "ignore_above": 256 } } } } } } } } } }然后您就可以抓住基于前缀的唯一字段。
Then you can grab the unique fields based on the prefix.
更多推荐
在Elasticsearch 5中汇总
发布评论