ElasticSearch - 如何从聚合中排除过滤器? [英] ElasticSearch - how to exclude filter from aggregations?

查看:524
本文介绍了ElasticSearch - 如何从聚合中排除过滤器?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我已经过滤了3个过滤器的查询:query:iphone,color:5,category:10,brand:25



如何获取每个品牌的$ code颜色:5 和类别:10



在Solr中,我做到了:

  fq = {!tag = tag_facet_brand} facet_brand:564& facet.field = {!ex = tag_facet_brand} facet_brand 

如何从聚合上下文中排除1个过滤器? (我不能使用全局,因为我松动查询:iphone ,我不能使用post_filter - 因为性能)。

解决方案

我们正在从SOLR移转,我们面临着同样的问题。



你可以尝试全球桶为查询过滤器添加每个桶:

 filter:{
query:{
query_string
查询:iPhone
}
}
}

你应该结束如下:

  {
size:10,
query:{
query_string:{
query:iphone
}
},
filter:{
bool:{
must:[
{
term:{
brand:564
}
},
{
term:{
color 5
}
},
{
term:{
category:10
}
}

$ b},
aggs:{
all:{
global:{},
aggs :{
关键字:{
过滤器:{
bool:{
必须:[
{
查询 :{
query_string:{
查询:iphone
}

},
{
term:{
color:5
}
},
{
term:{
category:10
}
}
]
}
},
:{
brand:{
terms:{
field:brand
}
}
}
}
}
}
}
}


I have filtered query with 3 filters: "query": "iphone", color:5, category:10, brand:25.

How can I get amount of products in each brand which have color:5 and category:10?

In Solr I did it like:

fq={!tag=tag_facet_brand}facet_brand:"564"&facet.field={!ex=tag_facet_brand}facet_brand

How can I exclude 1 filter from aggregation context? (I can't use global, because I loose query:iphone, I can't use post_filter - because of performance).

解决方案

We are just moving from SOLR and we are facing the same issue.

You could try global bucket then add a query filter for each bucket :

"filter" : {
            "query" : {
                "query_string" : {
                    "query" : "iPhone"
                }
            }
        }

You should end with something like :

{
    "size": 10,
    "query": {
        "query_string": {
            "query": "iphone"
        }
    },
    "filter": {
        "bool": {
            "must": [
                {
                    "term": {
                        "brand": "564"
                    }
                },
                {
                    "term": {
                        "color": "5"
                    }
                },
                {
                    "term": {
                        "category": "10"
                    }
                }
            ]
        }
    },
    "aggs": {
        "all": {
            "global": {},
            "aggs": {
                "keyword": {
                    "filter": {
                        "bool": {
                            "must": [
                                {
                                    "query": {
                                        "query_string": {
                                            "query": "iphone"
                                        }
                                    }
                                },
                                {
                                    "term": {
                                        "color": "5"
                                    }
                                },
                                {
                                    "term": {
                                        "category": "10"
                                    }
                                }
                            ]
                        }
                    },
                    "aggs": {
                        "brand": {
                            "terms": {
                                "field": "brand"
                            }
                        }
                    }
                }
            }
        }
    }
}

这篇关于ElasticSearch - 如何从聚合中排除过滤器?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆