【发布时间】:2021-01-25 23:57:44
【问题描述】:
我正在使用过滤器构建产品列表页面。有很多过滤器,它们的数据在带有聚合函数的 ES 中计数。 最低/最高价格的最简单示例:
{
"size": 0,
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"bool": {
"must": [
{
"term": {
"shop_id": 44
}
},
{
"term": {
"CategoryId": 36898
}
},
{
"term": {
"products_status": 1
}
},
{
"term": {
"availability": 3
}
}
]
}
}
}
},
"aggs": {
"min_price": {
"min": {
"field": "products_price"
}
},
"max_price": {
"max": {
"field": "products_price"
}
}
}
}
因此,ES 中的此请求根据过滤器中安装的规则(category_id 36898、shop_id 44 等)返回我的最低和最高价格。 它运行良好。
问题是:是否可以更新此请求并在没有过滤器的情况下获取聚合?或者是否有可能在一个请求中返回带有另一个过滤器的聚合数据?
所以我想要:
过滤数据的 min_price 和 max_price (query1)
还有 mix_price 和 max_price 用于未过滤的数据(或使用查询 2 过滤的数据)?
【问题讨论】:
-
嘿,谢谢你的问题:你的查询返回 "without_filter_max" => 数组:2 [▼ "doc_count" => 20 "price_value" => 数组:1 [▼ "value" = > 583.0 ] ] 是否可以让结果看起来像这样:"without_filter_max" => array:1 [▼ "value" => 583.0 ] ??
标签: elasticsearch