How to implement an andFilter for a list of filters in ES 2.x?


(apanimesh061) #1

In version 1.4.2 in AndFilterBuilder.java for building and filters we have:

   public AndFilterBuilder(FilterBuilder... filters) {
        for (FilterBuilder filter : filters) {
            this.filters.add(filter);
        }
    }

Since, in version 2.0 and above we have integrated the filters with query. I cannot figure out how will I do this in those versions?

I thought of using it this way:

 public QueryBuilder createAndFilter(List<QueryBuilder> someFilters) {
    QueryBuilder temp = boolQuery().must(someFilters.get(0));
    for (int i = 1; i < someFilters.size(); i++)
      temp = boolQuery().must(someFilters.get(i));
    return temp;
  }

Is it correct?


(system) #2