你可以用
should
和
exists
条款。假设您有以下两个文档:
// Document 1
{
"body": "quick brown fox",
"body_edited": null
}
// Document 2
{
"body": "quick brown fox",
"body_edited": "jumps over the lazy dog"
}
下面是搜索术语“brown fox”的示例:
"query": {
"bool": {
"should": [
{
"match": {
"body_edited": "brown fox"
}
},
{
"bool": {
"must": {
"match": {
"body": "brown fox"
}
},
"must_not": {
"exists": {
"field": "body_edited"
}
}
}
}
]
}
}
尽管事实上
body
文档2中的字段也符合我们的搜索条件。