Sri*_*ram 5 elasticsearch elasticsearch-2.0 elasticsearch-aggregation
示例文件:
{
"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"
}
]
}
Run Code Online (Sandbox Code Playgroud)
预期输出:
{
"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
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
我的查询:
我可以使用以下查询获得“ attribCount ”聚合。但我不知道如何获得每个属性值计数。
{
"query": {
"filtered": {
"query": {
"match_all": {}
}
}
},
"aggs": {
"attribCount": {
"terms": {
"field": "attributes.name",
"size": 0
}
}
},
"size": 0
}
Run Code Online (Sandbox Code Playgroud)
当我使用attributes.value 进行聚合时,它给出了总体计数。但我需要在预期输出中给出的名称值下列出它。
小智 5
正如您所说,属性字段是嵌套的。试试这个,这会奏效
{
"size": 0,
"aggs": {
"count": {
"nested": {
"path": "attributes"
},
"aggs": {
"attribCount": {
"terms": {
"field": "attributes.name"
}
},
"attribVal": {
"terms": {
"field": "attributes.name"
},
"aggs": {
"attribval2": {
"terms": {
"field": "attributes.value"
}
}
}
}
}
}
}
}
Run Code Online (Sandbox Code Playgroud)
| 归档时间: |
|
| 查看次数: |
15569 次 |
| 最近记录: |