[英]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.