[英]How to handle multiple 'and' 'or' operators in Elastic search Querybuilder in java
I have a POST body JSON which has one of the input as below我有一个 POST 正文 JSON,它具有如下输入之一
q = (a=1 and b=2 or c=3 and d=8)
I need to form a querybuilder elastic query using java我需要使用java形成一个querybuilder弹性查询
BoolQueryBuilder qb = QueryBuilders.boolQuery();
qb1= QueryBuilders.matchQuery("a", "1");
qb2= QueryBuilders.matchQuery("b", "2");
qb3= QueryBuilders.matchQuery("c", "1");
qb4= QueryBuilders.matchQuery("d", "1");
qb.must(qb1);
qb.must(qb2);
qb.should(qb3);
qb.must(qb4);
Will elastic search take care of the and operation to be done first and then or to be considered.弹性搜索是否会先处理和操作,然后再考虑。
How to I handle multiple and and or combinations (user is free to type anything ).如何处理多个和和或组合(用户可以自由输入任何内容)。 I am new to Elastic search would appreciate some help
我是 Elastic 搜索的新手,希望得到一些帮助
sharing a pseudo code, hope it helps分享一个伪代码,希望有帮助
elasticbuilder.boolQuery().should([
elasticbuilder.boolQuery().must([
elasticbuilder.matchQuery(1)
elasticbuilder.matchQuery(2)
])
elasticbuilder.boolQuery().must([
elasticbuilder.matchQuery(3)
elasticbuilder.matchQuery(4)
])
])
Usually I just create an example query in Kibana and then 'translate' it to the Java client api.通常我只是在 Kibana 中创建一个示例查询,然后将它“翻译”到 Java 客户端 api。 Not sure if this applies to you but if you want to create a full text search you could provide hints to the user as per how it is in ES docs .
不确定这是否适用于您,但如果您想创建全文搜索,您可以根据ES 文档中的内容向用户提供提示。
The simple_query_string query supports the following operators: + signifies AND operation | signifies OR operation - negates a single token " wraps a number of tokens to signify a phrase for searching * at the end of a term signifies a prefix query ( and ) signify precedence ...
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.