多个过滤器和弹性搜索中的聚合
发布时间:2020-12-14 04:31:13 所属栏目:百科 来源:网络整理
导读:如何使用与弹性搜索中的聚合相关联的过滤器? 官方文档仅给出了filter和aggregations的简单示例,并没有对查询dsl的正式描述 – 比较它。与postgres documentation。 通过尝试,我发现以下查询,这是通过elasticsearch(没有解析错误)接受,但忽略给定的过滤
如何使用与弹性搜索中的聚合相关联的过滤器?
官方文档仅给出了filter和aggregations的简单示例,并没有对查询dsl的正式描述 – 比较它。与postgres documentation。 通过尝试,我发现以下查询,这是通过elasticsearch(没有解析错误)接受,但忽略给定的过滤器: { "filter": { "and": [ { "term": { "_type": "logs" } },{ "term": { "dc": "eu-west-12" } },{ "term": { "status": "204" } },{ "range": { "@timestamp": { "from": 1398169707,"to": 1400761707 } } } ] },"size": 0,"aggs": { "time_histo": { "date_histogram": { "field": "@timestamp","interval": "1h" },"aggs": { "name": { "percentiles": { "field": "upstream_response_time","percents": [ 98.0 ] } } } } } } 有些人建议使用查询而不是过滤器。但官方文档通常建议the opposite对精确值进行过滤。查询的另一个问题是:当过滤器提供 有人可以指出文档,博客或书籍,它们描述了编写非平凡查询:至少一个聚合加多个过滤器。
我最终使用了
filter aggregation – 未过滤的查询。所以现在我有3个嵌套的aggs元素。
我也使用布尔过滤器,而不是由@ alex-brasetvik推荐,因为http://www.elasticsearch.org/blog/all-about-elasticsearch-filter-bitsets/ 我的最终实现: { "aggs": { "filtered": { "filter": { "bool": { "must": [ { "term": { "_type": "logs" } },{ "term": { "dc": "eu-west-12" } },{ "term": { "status": "204" } },{ "range": { "@timestamp": { "from": 1398176502000,"to": 1400768502000 } } } ] } },"aggs": { "time_histo": { "date_histogram": { "field": "@timestamp","interval": "1h" },"aggs": { "name": { "percentiles": { "field": "upstream_response_time","percents": [ 98.0 ] } } } } } } },"size": 0 } (编辑:李大同) 【声明】本站内容均来自网络,其相关言论仅代表作者个人观点,不代表本站立场。若无意侵犯到您的权利,请及时与联系站长删除相关内容! |