[英]Keep the documents with a missing field in the filter query results
我正在使用以下查询查询索引:
GET /dbpedia201510/entity/_search { "from": 0, "size": 10000, "query": { "bool": { "must": { "query_string":{ "fields": ["name","alias","pseudonyme"], "query": "Elias~ Franck~", "default_operator": "OR", "fuzziness": "auto" } }, "filter": { "bool": { "must": [ { "terms": { "job.keyword":["Architect","Politician","Tailor"] } } ] } } } } }
job
字段是一个字符串数组,查询的工作方式与预期的一样。 但是,有些文档没有job
字段,我也想获取这些文档。
我怎样才能做到这一点?
您需要在此处使用should clause
,该should clause
在任何一个job
字段存在且匹配术语查询或 job
字段不存在时匹配。
您的最终查询应如下所示:
GET /dbpedia201510/entity/_search
{
"from": 0,
"size": 10000,
"query": {
"bool": {
"must": {
"query_string": {
"fields": ["name","alias","pseudonyme"],
"query": "Elias~ Franck~",
"default_operator": "OR",
"fuzziness": "auto"
}
},
"filter": {
"bool": {
"should": [
{
"terms": {
"job.keyword": ["Architect","Politician","Tailor"]
}
},
{
"bool": {
"must_not": {
"exists": {
"field": "job"
}
}
}
}
]
}
}
}
}
}
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.