樣本文件:Elasticsearch數組值計數聚集
{
"id": "62655",
"attributes": [
{
"name": "genre",
"value": "comedy"
},
{
"name": "year",
"value": "2016"
}
]
}
{
"id": "62656",
"attributes": [
{
"name": "genre",
"value": "horror"
},
{
"name": "year",
"value": "2016"
}
]
}
{
"id": "62657",
"attributes": [
{
"name": "language",
"value": "english"
},
{
"name": "year",
"value": "2015"
}
]
}
期望輸出:
{
"hits" : {
"total": 3,
"hits": []
},
"aggregations": {
"attribCount": {
"language": 1,
"genre": 2,
"year": 3
},
"attribVals": {
"language": {
"english": 1
},
"genre": {
"comedy": 1,
"horror": 1
},
"year": {
"2016": 2,
"2015": 1
}
}
}
}
我的查詢:
我能得到 「attribCount」股份公司使用下面的查詢進行gregation。但我不知道如何獲取每個屬性值。
{
"query": {
"filtered": {
"query": {
"match_all": {}
}
}
},
"aggs": {
"attribCount": {
"terms": {
"field": "attributes.name",
"size": 0
}
}
},
"size": 0
}
當我使用attributes.value進行聚合時,它給出了總數。但是我需要在名稱值下面列出預期輸出中給出的值。
https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-bucket-nested-aggregation.html – blackmamba
@blackmamba我已經看了在它。它不清楚如何完成我的要求。當我給路徑作爲「屬性」時,我得到異常。當我給「attributes.name」,它得到計數爲0 – Sriram
你已經映射屬性和它的父親作爲嵌套的權利? – blackmamba