how to migrate from filterBuilder to higher version of elasticsearch code example

Example: how to migrate from filterBuilder to higher version of elasticsearch

// Code in 1.6
FilterBuilder filterBuilder = FilterBuilders.boolFilter()
  .should(
    FilterBuilders.boolFilter().must(
      QueryFilters.hostTeam(teamName),
      QueryFilters.hostGoals(scoredGoals, RangeModes.GTE),
      QueryFilters.guestGoals(scoredGoals, RangeModes.LT)
    ),
    FilterBuilders.boolFilter().must(
      QueryFilters.guestTeam(teamName),
      QueryFilters.guestGoals(scoredGoals, RangeModes.GTE),
      QueryFilters.hostGoals(scoredGoals, RangeModes.LT)
    )
);

// Code in 2.2
QueryBuilder filterBuilder = QueryBuilders.boolQuery()
  .should(
    QueryBuilders.boolQuery().must(QueryFilters.hostTeam(teamName))
      .must(QueryFilters.hostGoals(scoredGoals, RangeModes.GTE))
      .must(QueryFilters.guestGoals(scoredGoals, RangeModes.LT))
  )
  .should(
    QueryBuilders.boolQuery().must(QueryFilters.guestTeam(teamName))
      .must(QueryFilters.guestGoals(scoredGoals, RangeModes.GTE))
      .must(QueryFilters.hostGoals(scoredGoals, RangeModes.LT))
);

Tags:

Misc Example