我正在尝试针对电子商务应用构建带有方面过滤的产品搜索。对于产品品牌,我具有以下结构:
"brand": {
"type": "nested","properties": {
"name": {
"type": "text"
},"id": {
"type": "integer"
}
}
}
我想按品牌ID进行汇总,然后返回整个对象和文档数。像这样:
"brands" : {
"doc_count_error_upper_bound" : 0,"sum_other_doc_count" : 0,"buckets" : [
{
"key" : {
"name": "Apple","id": 1
},"doc_count" : 34
},{
"key" : {
"name": "Samsung","id": 2
},"doc_count" : 23
}
]
}
目前,我正在这样编写汇总:
"aggs": {
"brands": {
"nested": {
"path": "brand"
},"aggs": {
"brandIds": {
"terms": {
"field": "brand.id"
}
}
}
},}
结果看起来像这样:
"aggregations" : {
"brands" : {
"doc_count" : 15,"brandIds" : {
"doc_count_error_upper_bound" : 0,"buckets" : [
{
"key" : 1,"doc_count" : 4
},{
"key" : 2,"doc_count" : 2
}
]
}
}
}