带有多个过滤器的ElasticSearch

编程入门 行业动态 更新时间:2024-10-25 18:23:57
本文介绍了带有多个过滤器的ElasticSearch的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧! 问题描述

我正在尝试建立一个查询,该查询将找到所有用户文档(docType = user),然后根据许多过滤器对其进行过滤.例如位置,性别,年龄等.这些过滤器是根据我正在构建的搜索功能上的用户输入来添加/删除的.

I am trying to build a query that will find all user documents (docType = user) and then filter them based on many filters. Such as location, gender, age, etc. The filters are added / removed based on user input on the search function I'm building.

以下未返回任何结果:

{ "query": { "filtered": { "query": { "match_all": {} }, "filter": { "and": { "filters": [ { "term": { "doc.docType": "user" } }, { "term": { "doc.data.profile.location" : "CA" } } ] } } } } }

以下返回结果:

{ "query": { "filtered": { "query": { "field": { "doc.data.profile.location" : "CA" } }, "filter": { "and": { "filters": [ { "term": { "doc.docType": "user" } } ] } } } } }

后者虽然返回结果,但从长远来看是行不通的,因为我可能想添加一个针对年龄,性别等的额外过滤器,而且我似乎无法添加多个字段.如果我删除位置过滤器,则第一个查询有效.

The latter, although returning results, isn't going to work in the long run as I may want to include an extra filter for age, gender, etc and I can't seem to add multiple fields. The first query works if I remove the filter for location.

推荐答案

布尔过滤器允许您链接多个 MUST , SHOULD 和 SHOULD_NOT请求一起.允许您将其构造为一个查询.

The bool filter allows you to chain multiple MUST, SHOULD and SHOULD_NOT requests together. Allowing for you to construct this into one query.

更多推荐

带有多个过滤器的ElasticSearch

本文发布于:2023-10-13 20:34:42,感谢您对本站的认可!
本文链接:https://www.elefans.com/category/jswz/34/1489006.html
版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系,我们将在24小时内删除。
本文标签:多个   过滤器   ElasticSearch

发布评论

评论列表 (有 0 条评论)
草根站长

>www.elefans.com

编程频道|电子爱好者 - 技术资讯及电子产品介绍!