答案 0 :(得分:2)
您应按所需货币过滤查询,并使用术语汇总进行汇总
棘手的部分是强制Elasticsearch获得所有可能的国家。这可以使用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
}
}
}
}
您可以在this notebook
中查看此答案的示例执行情况