admin管理员组文章数量:1417691
I have an ElasticSearch query like below, where I try to take the aggregations, filter with bucket_filter then do pagination with bucket_paging. If I execute this exact query, I get the correct output as expected. But if I switch the order of bucket_filter and bucket_paging in query, it returns less documents than expected. As guess that, with the later case, ElasticSearch executes the bucket_paging paging first (that return max 50 items), then applies the bucket_filter filter, that in turn filters out a few more items from previous 50 items. Is my assumption correct? And if yes, is there any way to customize the query to get the expected result without being affected by mentioned aggregations' order in query.
My problem is, I'm using elasticsearch-java client library to build the query, which put aggregations into a map instead of a list, as a result the order of aggregations are random in the final built query.
Note: I'm on ElasticSearch v8.7
{
"aggregations": {
"by_planning_sum_id": {
"aggregations": {
"bad_count": {
"filter": {
"bool": {
"must": [{ "term": { "review_score_class": { "value": "bad" } } }]
}
}
},
"country_data": {
"aggregations": {
"avg_score": { "avg": { "field": "review_score" } }
},
"filter": {
"bool": {
"must": [{ "term": { "region_code": { "value": "JP" } } }]
}
}
},
"bad_ratio": {
"bucket_script": {
"buckets_path": { "all": "_count", "bad": "bad_count>_count" },
"script": { "source": "params.bad/params.all" }
}
},
"zero_flag": {
"bucket_script": {
"buckets_path": { "count": "country_data>_count" },
"gap_policy": "insert_zeros",
"script": { "source": "return ((params.count == 0) ? 0 : 1)" }
}
},
"quality_negative_count": {
"filter": {
"bool": {
"must": [
{ "term": { "quality_label_class": { "value": "negative" } } }
]
}
}
},
"avg_score": { "avg": { "field": "review_score" } },
"bucket_filter": {
"bucket_selector": {
"buckets_path": { "count": "_count" },
"script": { "source": "params.count>=30" }
}
},
"bucket_paging": {
"bucket_sort": {
"from": 0,
"size": 50,
"sort": [
{ "zero_flag": { "order": "desc" } },
{ "country_data>avg_score": { "order": "desc" } },
{ "avg_score": { "order": "desc" } },
{ "_key": { "order": "desc" } }
]
}
}
},
"terms": { "field": "root_planning_sum_id", "size": 10000 }
}
},
"query": "..."
}
本文标签: Does order of aggregation in ElasticSearch query affect final search resultStack Overflow
版权声明:本文标题:Does order of aggregation in ElasticSearch query affect final search result - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1745274084a2651072.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论