【发布时间】:2017-03-20 18:38:33
【问题描述】:
我有orders这样的文件:
{
"customer":{
"id":1,
"Name":"Foobar"
},
"products":[
{
"id":1,
"name":"Television",
"category": 11
},
{
"id":2,
"name":"Smartphone",
"category": 12
}
]
}
我正在执行top_terms_aggregation 以了解最畅销的产品。为了在全球范围内做到这一点,我使用:
{
"size":0,
"aggs":{
"products":{
"nested":{
"path":"products"
},
"aggs":{
"top_terms_aggregation":{
"terms":{
"field":"products.id",
"size":10
}
}
}
}
}
}
但是,我将如何过滤给定 category_id 的产品?我尝试添加此过滤器:
"query":{
"bool":{
"must":[
{
"match":{
"products.category":11
}
}
]
}
}
但这会过滤具有给定类别的一些产品的订单本身,并且聚合会损坏。
我想获得属于特定类别的畅销产品。
【问题讨论】:
-
不能解决我的问题:我必须保持
nested-path标准并过滤适合整数类别 ID 的文档。
标签: elasticsearch nosql-aggregation nosql