我試圖在elasticsearch中查找聚合結果的最小值和最大值。什麼查詢將允許它先通過字段進行彙總,然後執行月度子彙總以獲取該字段的月度數據,然後在那些每月計算的度量標準中查找最小值和最大值。 我被困在發現min
和max
。對於以下要求的其餘部分是我的查詢elasticsearch min和max在其他聚合結果上的合併
這個問題可以表述爲:什麼是在任何國家的最大和最小交易(考慮所有月份)? 這裏,我試圖查詢:
{
"query": {
"bool": {
"must": [
{
"term": {
"Id": "7466swy7893jgs225"
}
}
]
}
},
"aggs": {
"dimension": {
"terms": {
"field": "country"
},
"aggs": {
"MoM": {
"date_histogram": {
"field": "date",
"interval": "month",
"format": "MMM YY"
},
"aggs": {
"totalValue": {
"sum": {
"field": "Transactions"
}
}
}
}
}
}
},
"size": 0
}
這是我得到的輸出:
{
"aggregations": {
"dimension": {
"doc_count_error_upper_bound": 0,
"sum_other_doc_count": 0,
"buckets": [
{
"key": "USA",
"doc_count": 392,
"MoM": {
"buckets": [
{
"key_as_string": "jan 16",
"key": 1462060800000,
"doc_count": 31,
"totalValue": { "value": 352 }
},
{
"key_as_string": "Feb 16",
"key": 1462060800000,
"doc_count": 31,
"totalValue": { "value": 429 }
}
??????????????/MIN and MAX of 352 AND 429
]
}
},
{
"key": "Bhutan",
"doc_count": 392,
"MoM": {
"buckets": [
{
"key_as_string": "Jan 16",
"key": 1462060800000,
"doc_count": 31,
"totalValue": {"value": 750 }
}
,
{
"key_as_string": "Feb 16",
"key": 1464739200000,
"doc_count": 30,
"totalValue": {"value": 827 }
}
??????????????/MIN and MAX of 750 AND 827
]
}
}
]
}
}}
i一定會嘗試一下。我看起來很有道理。謝謝! – anekix
樂於幫忙.. – Richa