在Elasticsearch 5中汇总_field_names [英] Aggregating over _field_names in elasticsearch 5

查看:340
本文介绍了在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中汇总_field_names的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆