在Elasticsearch 5中汇总

编程入门 行业动态 更新时间:2024-10-26 09:30:07
本文介绍了在Elasticsearch 5中汇总_field_names的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试按照> 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中汇总

本文发布于:2023-11-22 07:02:57,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1616427.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:Elasticsearch

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!