How to construct a boolquery dynamically in java api?

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:

QueryBuilder qb = QueryBuilders
.boolQuery()
.must(matchPhraseQuery("body", "some text"))
.should(termQuery1)
.should(termQuery2)
.....
.should(termQueryN);

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

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:

QueryBuilder qb = QueryBuilders
.boolQuery()
.must(matchPhraseQuery("body", "some text"))
.should(termQuery1)
.should(termQuery2)
.....
.should(termQueryN);

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

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);

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

I just add a link to this: Elasticsearch Platform — Find real-time answers at scale | Elastic

--
David :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

Le 1 avr. 2013 à 20:13, mkleen mkleen@gmail.com a écrit :

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);

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Hi David,

new documentation is excellent, though not so sure about the new design.
Maybe i just need to get used to it :slight_smile:

Michael

On Monday, April 1, 2013 8:46:46 PM UTC+2, David Pilato wrote:

I just add a link to this:
Elasticsearch Platform — Find real-time answers at scale | Elastic

--
David :wink:
Twitter : @dadoonet / @elasticsearchfr / @scrutmydocs

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.

Hi Michael,

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);

--
You received this message because you are subscribed to the Google Groups "elasticsearch" group.
To unsubscribe from this group and stop receiving emails from it, send an email to elasticsearch+unsubscribe@googlegroups.com.
For more options, visit https://groups.google.com/groups/opt_out.