Elasticsearch查询与分析全解析
1. 过滤查询字段存在性
在Elasticsearch中,我们可以使用过滤器来查询字段的存在性。例如,使用以下命令查询 get-together 索引中 reviews 字段不存在的文档:
% curl 'localhost:9200/get-together/_search' –d '
{
"query": {
"filtered": {
"query": {
"match_all": {}
},
"filter": {
"missing": {
"field": "reviews",
"existence": false,
"null_value": true
}
}
}
}
}'
这里的 missing 过滤器会匹配 reviews 字段不存在、为空或者值为 null 的文档。需要注意的是, missing 和 exists 过滤器默认是会被缓存的。
2. 将任意查询转换为过滤器
有时候,我们可能需要将一些没有对应过滤器的查询(如 query_string 查询)转换为过滤器。Elasticsearc
超级会员免费看
订阅专栏 解锁全文
1741

被折叠的 条评论
为什么被折叠?



