应找到以下文件:
matches query 'my text' AND (has not field OR field with value)
我尝试了以下内容:
GET /myIndex/_search
{
"query": {
"bool": {
"must": [
{
"query_string": {
"query": "my text"
}
},
{
}
],
"filter": {
"bool": {
"must_not": {
"exists": {
"field": "myField"
}
},
"must": {
"terms": {
"myField": [
"myValue"
]
}
}
}
}
}
}
}
它应该(但不)工作谎言:
must
和filter
部分must
按查询选择must and
must_not` 但这类似于must
与must_not
通过 AND 子句相结合。例如。当我删除"必须"或者" must_not"查询工作。
如何更改查询以及#34;必须"用" must_not"通过 OR 条款?
Elasticsearch版本为5.3.2
答案 0 :(得分:1)
bool filter
和must
条之间需要额外must_not
。
您还应该考虑 myField 字段。如果它被定义为文本或关键字。 使用elasticsearch 5.6.1进行测试以下查询有效:
{
"query": {
"bool": {
"must": [{
"query_string": {
"query": "this is a text content"
}
}],
"filter": {
"bool": {
"should" : [{
"bool" : {
"must_not": {
"exists": {
"field": "myField"
}
}
}
},
{
"bool" : {
"must": {
"terms": {
"myField.keyword": ["my field exists and has a value"]
}
}
}
}]
}
}
}
}
}