How to do multiple filter query in Elasticsearch using Java?
You can use the terms
query instead of multiple term
queries:
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery()
.must(QueryBuilders.simpleQueryStringQuery(query).field("newContent").field("T"))
.filter(QueryBuilders.termsQuery(Collection, "abc", "xyz"));
^ ^ ^
| | |
use termsQuery with multiple values
UPDATE
I'm surprised your code compiles at all because you're missing some closing parenthesis, just rewrite your query like this and it should work:
BoolQueryBuilder boolQuery = QueryBuilders.boolQuery()
.must(QueryBuilders.simpleQueryStringQuery(query).field("newContent").field("T"))
.filter(QueryBuilders.termQuery(Collection[0], "true"))
.filter(QueryBuilders.termQuery(Collection[1], "true"));