Adding more than one filter on javaAPI ES


(SamElasticSearch) #1

All
How do I add more than one field on querybuilder?
eg:
This query will list all the items that has "color" equals to "red"
QueryBuilder queryBuilder1 = QueryBuilders.termQuery("color", "red");

But I want to add "and" on the queryBuilder1 as list all the items that has "color" equals to "red" and "room" equals to "kitchen".

QueryBuilder queryBuilder2 = QueryBuilders.termQuery("room", "kitchen");

How can I combine both queryBuilder1 and queryBuilder2 in one single queryBuilder?
Thanks


(SamElasticSearch) #2

I can do this w/ boolQuery. Is there any other way to do it?

QueryBuilder queryBuilder = QueryBuilders.boolQuery()
.must(QueryBuilders.termQuery("color", "red"))
.must(QueryBuilders.termQuery("room", "kitchen"))
;


(system) #3