[英]elasticsearch - how to aggregate and filter by multiple rows
You should filter queries by desired currencies and aggregate them with a term aggregation. 您应按所需货币过滤查询,并用术语汇总对其进行汇总。
The tricky part is force Elasticsearch to get all possible countries. 棘手的部分是迫使Elasticsearch获得所有可能的国家。 This can be done using size=0 parameter in terms aggregation
这可以通过在聚合中使用size = 0参数来完成
currencies_criteria = [1,2]
elasticsearch_query = {
"query": {
"filtered": {
"filter": {
"bool": {
"must" : [
{
"term": {"currency" : currencies_criteria}
}
]
}
}
}
},
"aggs" : {
"country_count" : {
"terms" : {
"field" : "country",
#https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-terms-aggregation.html#search-aggregations-bucket-terms-aggregation-approximate-counts
"size" : 0
}
}
}
}
You can see the sample execution of this answer in this notebook 您可以在此笔记本中看到此答案的示例执行
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.