gpt4 book ai didi

elasticsearch - 当我在indexest hat上查询时,为什么 “must_not”不起作用不包含该术语。

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

我有一个如下所示的ES索引:

     "_source" : {
"text_terms" : [
{
"term" : "aaa",
"freq" : 1
},
{
"term" : "西门子",
"freq" : 1
},
{
"term" : "ccc",
"freq" : 1
}
]
}

映射在这里:
        "text_terms":{
"type":"nested",
"properties":{
"term":{
"type":"string",
"index":"not_analyzed"
},
"freq":{
"type":"integer"
}
}
}

现在我想查询包含 西门子的文档
"query": {
"nested": {
"query": {
"bool": {
"must": [{
"term": {
"text_terms.term": "西门子" }
}]
}
},
"path": "text_terms"
}
}

有用。但是当我想查询不包含 西门子的文档时
"query":
{ "nested":
{ "query": {
"bool": {
"must_not": [{
"term": {
"text_terms.term": "西门子" }
}]
}
},
"path": "text_terms" }
}

为什么这次不起作用,我可以查询所有文档,甚至不包含 西门子,例如
   "_source" : {
"text_terms" : [
{
"term" : "ddd",
"freq" : 1
},
{
"term" : "eee",
"freq" : 1
}
]
}

最佳答案

this issue我知道正确的查询,即应将must_not放在nested之外,请参见下文

"query": {
"bool": {
"must_not": {
"nested": {
"path": "text_terms",
"query": {
"term": {
"text_terms.term": "西门子"
}
}
}
}
}
}

关于elasticsearch - 当我在indexest hat上查询时,为什么 “must_not”不起作用不包含该术语。,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51480217/

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