大佬教程收集整理的这篇文章主要介绍了如何从Filter Aggregation返回的文档集中将当前聚合上下文缩小到特定范围?,大佬教程大佬觉得挺不错的,现在分享给大家,也给大家做个参考。
尝试以下聚合:
{ "aggs": { "conTinents": { "nested": { "path": "conTinents" }, "aggs": { "asia_conTinent": { "filter": { "query": { "match": { "conTinents.name": "asia" } } }, "aggs": { "countrIEs": { "nested": { "path": "conTinents.countrIEs" }, "aggs": { "india_country": { "filter": { "query": { "match": { "conTinents.countrIEs.name": "india" } } }, "aggs": { "states": { "nested": { "path": "conTinents.countrIEs.states" }, "aggs": { "count": { "value_count": { "fIEld": "conTinents.countrIEs.states.wins" } } } } } } } } } } } } } }
@H_801_7@解决方法
我有一个嵌套的对象映射,示例数据:
{ "_index": "simpleindex","_type": "games","_id": "AU_eC-Uzt6KxlUliF68N","_score": 1,"_source": { "conTinents": [ { "name": "Asia","countries": [ { "name": "India","states": [ { "name": "TN","game": "soccor","wins": 1 } ] },{ "name": "India","states": [ { "name": "KA","wins": 1 } ] } ] } ] } },{ "_index": "simpleindex","_id": "AU_eCf5dt6KxlUliF637","_id": "AU_eDIdXt6KxlUliF69i",{ "name": "Pak","states": [ { "name": "NA","wins": 1 } ] } ] } ] } }
@H_801_7@这是我的过滤汇总,可返回与过滤条件匹配的文档(即,大陆应为“亚洲”,国家应为“印度”):
{ "aggs": { "DocumentSet": { "filter": { "and": { "filters": [ { "nested": { "path": "conTinents","query": { "match": { "conTinents.name": "asia" } } } },{ "nested": { "path": "conTinents.countries","query": { "match": { "conTinents.countries.name": "india" } } } } ] } },"aggs": { "conTinents": { "nested": { "path": "conTinents" },"aggs": { "countries": { "nested": { "path": "conTinents.countries" },"aggs": { "states": { "nested": { "path": "conTinents.countries.states" },"aggs": { "count": { "value_count": { "field": "conTinents.countries.states.wins" } } } } } } } } } }}}
@H_801_7@这是结果(副本仅将聚合粘贴到此处):
"aggregations": { "DocumentSet": { "doc_count": 3,"conTinents": { "doc_count": 3,"countries": { "doc_count": 6,"states": { "doc_count": 6,"count": { "value": 6 } } } } } }
@H_801_7@我的意图是仅从中获得“胜利”
conTinents.name=asia AND countries.name=india
。过滤器可以按预期工作,但是我只需要将聚合范围缩小到countries.name=india
;
本质上是Filter聚合返回的文档的作用域的另一个级别,因此叶聚合计数为5而不是6。大佬总结
以上是大佬教程为你收集整理的如何从Filter Aggregation返回的文档集中将当前聚合上下文缩小到特定范围?全部内容,希望文章能够帮你解决如何从Filter Aggregation返回的文档集中将当前聚合上下文缩小到特定范围?所遇到的程序开发问题。
如果觉得大佬教程网站内容还不错,欢迎将大佬教程推荐给程序员好友。
本图文内容来源于网友网络收集整理提供,作为学习参考使用,版权属于原作者。
如您有任何意见或建议可联系处理。小编QQ:384754419,请注明来意。