gpt4 book ai didi

elasticsearch - Elasticsearch,将嵌套过滤器与普通过滤器结合

转载 作者:行者123 更新时间:2023-12-02 22:32:41 24 4
gpt4 key购买 nike

我想出了如何在Elasticsearch中映射和过滤嵌套查询。好极了!但是,尚无法解决的是同时过滤“普通”过滤器和嵌套过滤器。您在此处看到的示例没有给出错误,并且第二个(嵌套的)过滤器似乎正在运行,但第一个过滤器却没有。在此示例中,我希望包括两个过滤器,而不仅仅是一个。我究竟做错了什么?

{
"size": 100,
"sort": [],
"query": {
"filtered": {
"query": {
"match_all": []
},
"filter": {
"bool": {
"must": [
{
"terms": {
"category.untouched": [
"Chargers"
]
}
}
],
"should": [],
"must_not": {
"missing": {
"field": "model"
}
}
}
},
"filter": {
"nested": {
"path":"phones",
"filter":{
"bool": {
"must": [
{
"term": {
"phones.name.untouched":"Galaxy S3 Neo I9301"
}
}
]
}
}
}
},
"strategy": "query_first"
}
},
"aggs": {
"category.untouched": {
"terms": {
"field": "category.untouched"
}
},
"brand.untouched": {
"terms": {
"field": "brand.untouched"
}
},
"price_seperate": {
"histogram": {
"field": "price_seperate",
"interval": 10,
"min_doc_count": 1
}
},
"phones.name.untouched": {
"nested": {
"path": "phones"
},
"aggs": {
"phones.name.untouched": {
"terms": {
"field": "phones.name.untouched"
}
}
}
}
}
}

最佳答案

您有两个名为"filter"的键(在"filtered"中),因此其中之一将被忽略。您可能只需要将两个过滤器包装在"bool"中即可( bool(boolean) 值可以根据需要嵌套)。

我无法在不设置一些测试数据的情况下对其进行测试,但是请尝试一下,看看是否能使您更接近:

{
"size": 100,
"sort": [],
"query": {
"filtered": {
"query": {
"match_all": []
},
"filter": {
"bool": {
"must": [
{
"terms": {
"category.untouched": [
"Chargers"
]
}
},
{
"nested": {
"path": "phones",
"filter": {
"term": {
"phones.name.untouched": "Galaxy S3 Neo I9301"
}
}
}
}
],
"should": [],
"must_not": {
"missing": {
"field": "model"
}
}
}
},
"strategy": "query_first"
}
},
"aggs": {
"category.untouched": {
"terms": {
"field": "category.untouched"
}
},
"brand.untouched": {
"terms": {
"field": "brand.untouched"
}
},
"price_seperate": {
"histogram": {
"field": "price_seperate",
"interval": 10,
"min_doc_count": 1
}
},
"phones.name.untouched": {
"nested": {
"path": "phones"
},
"aggs": {
"phones.name.untouched": {
"terms": {
"field": "phones.name.untouched"
}
}
}
}
}
}

关于elasticsearch - Elasticsearch,将嵌套过滤器与普通过滤器结合,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/30461207/

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