[英]Filter grouping in Elastic Search
我有一個查詢,該查詢根據給定的過濾器匯總數據,如下所述。
{
"size": 0,
"aggs": {
"country": {
"terms": {
"field": "country",
"size": 10,
"order": {
"messages": "desc"
}
},
"aggs": {
"messages": {
"sum": {
"field": "count"
}
}
}
}
}
},
"query": {
"bool": {
"must": [],
"filter": [
{
"terms": {
"country": [
"US", "FR"
]
}
},
{
"terms": {
"locale": [
"en_US", "en_FR"
]
}
}
]
}
}
}
此查詢返回的兩個國家的所有數據都具有區域設置(我在過濾器中提到)數據
例如:US-> en_US,en_FR和FR-> en_US,en_FR。
現在我想獲取US-> en_US和FR-> en_FR的數據 (這需要在查詢的Filters邏輯中進行框架化)。 並且還需要相應地進行匯總(基於國家/地區和過濾條件)
為此,我正在努力尋找或構築彈性搜索中的查詢。 任何建議都會有所幫助
您可以這樣做:
{
"size": 0,
"aggs": {
"country": {
"terms": {
"field": "country",
"size": 10,
"order": {
"messages": "desc"
}
},
"aggs": {
"messages": {
"sum": {
"field": "count"
}
}
}
}
},
"query": {
"bool": {
"must": [],
"minimum_should_match": 1,
"should": [
{
"bool": {
"filter": [
{
"term": {
"country": "US"
}
},
{
"term": {
"locale": "en_US"
}
}
]
}
},
{
"bool": {
"filter": [
{
"term": {
"country": "FR"
}
},
{
"term": {
"locale": "en_FR"
}
}
]
}
}
]
}
}
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.