Elastic search : Replacing BoolFilterBuilder from v0.9 to v6


(SatyaRaj) #1

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

(David Pilato) #2

That might be ok.

You can remove must() at the end BTW.


(SatyaRaj) #3

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


(David Pilato) #4

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


(SatyaRaj) #5

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


(David Pilato) #6

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


(SatyaRaj) #7

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


(David Pilato) #8

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.


(SatyaRaj) #9

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


(system) #10

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