Elastic search : Replacing BoolFilterBuilder from v0.9 to v6

Hi Team,

Can you please help me if the below code(es v0.9) can be replaced

BoolFilterBuilder filter = FilterBuilders.boolFilter().filterName("compositeFilter");
filterBuilder.must(FilterBuilders.termsFilter("keyword", toLowerCase(filterList)));

by the following (es v6)

BoolQueryBuilder query = QueryBuilders.boolQuery();
query.filter(QueryBuilders.termsQuery("keyword", toLowerCase(filterList))).must();

That might be ok.

You can remove must() at the end BTW.

Ohh.. Then how do I differentiate/specify must, mustnot while using boolquery as filter ?

You can add a bool within a bool.filter clause.

Hi Sir,

I'm missing something here. I don't completely understand.

query.filter(QueryBuilders.termsQuery("keyword", toLowerCase(filterList)));

The above snippet is what could be proper replacement.
I'm not getting how do we specify exact must clauses. Can you help me with similar code line.

Thank you,
Regards,
SatyaRaj

Why do you want to use must when you can use filter?

OK, So v6 is basically moving out of this must filter and then mustnot ?
My usecase is to usemustNot in some cases

yes.

Your original example was without must_not. But you can basically use filter to filter (no scoring), must_not to remove documents from the resultset, and mustor should if relevancy matters.

That helps. David..Will Use this way now. will keep you posted in case of any further issues.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.