elasticsearch 应用多个过滤器,通过elasticsearch聚合为单个指标
是否有一种方法(可能聚合聚合桶)在聚合中应用多个筛选器并使其返回单个度量值 例如,这里有一个聚合查询,其中我得到了所有具有option_id=16和category.id=870的产品的最小/最大价格
elasticsearch 应用多个过滤器,通过elasticsearch聚合为单个指标,
elasticsearch,
elasticsearch,是否有一种方法(可能聚合聚合桶)在聚合中应用多个筛选器并使其返回单个度量值 例如,这里有一个聚合查询,其中我得到了所有具有option_id=16和category.id=870的产品的最小/最大价格 { "aggregations": { "prices": { "filters": { "filters": { "category": {
{
"aggregations": {
"prices": {
"filters": {
"filters": {
"category": {
"terms": {
"category.id": [ 870 ]
}
},
"option": {
"terms": {
"option_id": [ 16 ]
}
}
}
},
"aggregations": {
"price_min": {
"min": {
"field": "variant.price_total"
}
},
"price_max": {
"max": {
"field": "variant.price_total"
}
}
}
}
}
}
不幸的是,这给了我两个不同的值:
{
"doc_count": 1450674,
"prices": {
"buckets": {
"category": {
"doc_count": 42979,
"price_min": {
"value": 0.49
},
"price_max": {
"value": 39998.99
}
},
"store": {
"doc_count": 100961,
"price_min": {
"value": 0.06
},
"price_max": {
"value": 644000
}
}
}
}
}
有没有办法将两个过滤器一起应用到一个度量/桶中?有。您需要使用聚合而不是
过滤器
聚合。查询如下所示:
{
"aggregations": {
"prices": {
"filter": {
"bool": {
"must": [
{
"terms": {
"category.id": [
870
]
}
},
{
"terms": {
"option_id": [
16
]
}
}
]
}
},
"aggregations": {
"price_min": {
"min": {
"field": "variant.price_total"
}
},
"price_max": {
"max": {
"field": "variant.price_total"
}
}
}
}
}
}
这将为
price\u min
和price\u max
提供一个指标,并应用这两个过滤器。非常好。这正是我想要的。