gpt4 book ai didi

elasticsearch - 匹配项析取

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

我是Elasticsearch的新手,并且发现查询DSL非常笨拙。我正在尝试返回与2个不同字段的多个值匹配的所有文档。这就是我构造查询的方式,但是它不起作用:

POST myindex/type/_search
{
"query": {
"filtered": {
"filter": {
"terms": {
"ref": ["1431007639", "1431007633"],
"advertiserName": ["Ad1", "ad2"]
}
}
}
}
}

如果可行,这应该返回所有ref字段为1431007639或1431007633的文档,以及(联合)所有AdvertiserName为Ad1或Ad2的文档。

如果我不考虑其中一个条件,则结果对于单个条件是正确的。当我以这种方式混合两种情况时,返回的文档数不正确。

知道这个的人可以帮助我创建一个简单的OR查询吗?

谢谢!!

最佳答案

同一terms过滤器中不能有多个字词过滤器。试试这个:

POST myindex/type/_search
{
"query": {
"filtered": {
"filter": {
"bool": {
"should": [
{
"terms" : {
"ref": ["1431007639", "1431007633"]
}
},
{
"terms" : {
"advertiserName": ["Ad1", "ad2"]
}
}
]
}
}
}
}
}

您可以在 ES bool filter docs中看到更多信息。

关于elasticsearch - 匹配项析取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/27391892/

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