[英]Combining query and filter on same field in elastic search
我有地址的doc类型,有城市作为字段。 城市领域使用分析仪
"keyword_analyzer": {
"tokenizer": "keyword", # So that we don't split multi word city name
"filter": ["lowercase"] # The search needs to case insensitive
}
如何获得与给定城市“X”或城市匹配的任何地址为空。 在sql中它将被写为
SELECT * FROM address
WHERE city = 'X' or city IS NULL
我想我必须使用匹配查询来获取city ='X'
和'missing'过滤器以获得city IS NULL
。 我该如何结合这个?
Elasticsearch允许将查询与bool查询组合在一起。 Bool查询有三个字段:
以下elasticsearch查询是一个包含should字段的布尔查询,包含两个子查询:
此查询的结果将等同于city = 'mycity' OR city IS NULL
:
{
"query": {
"bool": {
"should": [
{
"match": {
"city": "mycity"
}
},
{
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"missing": {
"field": "city"
}
}
}
}
]
}
}
}
一些有用的资源:
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.