我使用以下查询查询索引:
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
字段,我也希望得到这些文档。
我该怎么做?
答案 0 :(得分:4)
您需要在此使用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"
}
}
}
}
]
}
}
}
}
}
。
您的最终查询应如下所示:
<style name="AppTheme" parent="Theme.AppCompat.Light.DarkActionBar">