gpt4 book ai didi

elasticsearch - 使用和不使用过滤器的ElasticSearch聚合

转载 作者:行者123 更新时间:2023-12-02 23:01:00 25 4
gpt4 key购买 nike

我正在建立带有过滤器的产品列表页面。过滤器很多,并且具有聚合功能的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的过滤数据)?

最佳答案

您可以将global选项用于聚合,以不应用查询块中提供的任何过滤器。

例如,对于您的查询,请使用以下json输入。

{
“大小”:0,
“查询”:{
“已过滤”:{
“查询”:{
“match_all”:{}
},
“过滤器”:{
“ bool(boolean) ”:{
“必须”:[
{
“条款”:{
“shop_id”:44
}
},
{
“条款”:{
“CategoryId”:36898
}
},
{
“条款”:{
“products_status”:1
}
},
{
“条款”:{
“可用性”:3
}
}
]
}
}
}
},
“ags”:{
“最低价格”:{
“分钟”:{
“field”:“products_price”
}
},
“max_price”:{
“最大”:{
“field”:“products_price”
}
},
“without_filter_min”:{
“全局”:{},
“ags”:{
“价格值”: {
“分钟”:{
“field”:“products_price”
}
}
}
},
“without_filter_max”:{
“全局”:{},
“ags”:{
“价格值”: {
“最大”:{
“field”:“products_price”
}
}
}
}
}
}

关于elasticsearch - 使用和不使用过滤器的ElasticSearch聚合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/34399842/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com