In my program, I generated a list of termQuery dynamically and I want to
combine them into a boolquery. How could I implement it in java api? Thanks.
By the way, I want to accomplish the fuction as follows:
more specifically, I want to accomplish the following lucene code in ES.
BooleanQuery booleanQuery = new BooleanQuery();
booleanQuery.add(query1, BooleanClause.Occur.SHOULD);
booleanQuery.add(query2, BooleanClause.Occur.SHOULD);
On Monday, April 1, 2013 7:26:26 PM UTC+8, Jingang Wang wrote:
Hi there,
In my program, I generated a list of termQuery dynamically and I want to
combine them into a boolquery. How could I implement it in java api? Thanks.
By the way, I want to accomplish the fuction as follows:
In Elasticsearch, queries are built using the QueryBuilder interface, so
you are on the right track:
QueryBuilder finalQuery =
org.elasticsearch.index.query.QueryBuilders.boolQuery().should(query1).should(query2)
Michael
On Monday, April 1, 2013 1:56:35 PM UTC+2, Jingang Wang wrote:
more specifically, I want to accomplish the following lucene code in ES.
BooleanQuery booleanQuery = new BooleanQuery();
booleanQuery.add(query1, BooleanClause.Occur.SHOULD);
booleanQuery.add(query2, BooleanClause.Occur.SHOULD);
In Elasticsearch, queries are built using the QueryBuilder interface, so you are on the right track:
QueryBuilder finalQuery = org.elasticsearch.index.query.QueryBuilders.boolQuery().should(query1).should(query2)
Michael
On Monday, April 1, 2013 1:56:35 PM UTC+2, Jingang Wang wrote:
more specifically, I want to accomplish the following lucene code in ES.
BooleanQuery booleanQuery = new BooleanQuery();
booleanQuery.add(query1, BooleanClause.Occur.SHOULD);
booleanQuery.add(query2, BooleanClause.Occur.SHOULD);
Thanks for your reply, it's helpful.
At last, I accomplish the purpose as follows:
BoolQueryBuilder qb = QueryBuilders
.boolQuery()
.must(matchPhraseQuery("body", “text”));
then in every loop:
qb.should(termQuery(termQuery1));
On Tuesday, April 2, 2013 2:13:23 AM UTC+8, mkleen wrote:
Hi Jingang,
In Elasticsearch, queries are built using the QueryBuilder interface, so
you are on the right track:
QueryBuilder finalQuery =
org.elasticsearch.index.query.QueryBuilders.boolQuery().should(query1).should(query2)
Michael
On Monday, April 1, 2013 1:56:35 PM UTC+2, Jingang Wang wrote:
more specifically, I want to accomplish the following lucene code in ES.
BooleanQuery booleanQuery = new BooleanQuery();
booleanQuery.add(query1, BooleanClause.Occur.SHOULD);
booleanQuery.add(query2, BooleanClause.Occur.SHOULD);
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.