我有一个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
}
]
}发布于 2018-07-24 22:10:34
从this issue我知道正确的查询,那就是应该将must_not放在nested之外,如下所示
"query": {
"bool": {
"must_not": {
"nested": {
"path": "text_terms",
"query": {
"term": {
"text_terms.term": "西门子"
}
}
}
}
}
}https://stackoverflow.com/questions/51480217
复制相似问题