0
我在下面的格式如何使用elasticsearch方面查詢GROUPBY結果
{
"ID": { "Color": "Black", "Product": "Car" },
"ID": { "Color": "Black", "Product": "Car" },
"ID": { "Color": "Black", "Product": "Van" },
"ID": { "Color": "Black", "Product": "Van" },
"ID": { "Color": "Ash", "Product": "Bike" }
}
我要計算汽車的數量和相應顏色的JSON數據。我正在使用elasticsearch方面來做到這一點。
我查詢
$http.post('http://localhost:9200/product/productinfoinfo/_search?size=5', { "aggregations": { "ProductInfo": { "terms": { "field": "product" } } }, "facets": { "ProductColor": { "terms": { "field": "Color", "size": 10 } } } })
我得到的輸出像下面
"facets": { "ProductColor": { "_type": "terms", "missing": 0, "total": 7115, "other": 1448, "terms": [ { "term": "Black", "count": 4 }, { "term": "Ash","count":1} },
"aggregations": { "ProductInfo": { "doc_count_error_upper_bound": 94, "sum_other_doc_count": 11414, "buckets": [ { "key": "Car", "doc_count": 2 }, { "key": "Van", "doc_count": 2 }, { "key": "Bike", "doc_count": 1 } ] } } }
我真正想要的是,
[ { "key": "Car", "doc_count": 2, "Color":"Black", "count":2 }, { "key": "Van", "doc_count": 2,"Color":"Black", "count":2 }, { "key": "Bike", "doc_count": 1,"Color":"Ash", "count":1 } ]
我想GROUPBY結果。是否有可能在elasticsearch查詢中做到這一點。
在此先感謝
我們需要使用'」 aggs「或'」aggregation「' – Mangoski
這是完全一樣的東西:你可以同時使用,但我更喜歡使用'aggs',因爲它的輸入時間較短,但使用'aggregations'會產生相同的結果。 – ThomasC
還有一個疑問可以爲groupby添加更多aggs。它會起作用嗎? – Mangoski