样本文件: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