/** * <pre> * { * "bool": { * "should": [ * { * "match": { "{@param fields[0]}": "{@param searchText}" } * }, * { * "match": { "{@param fields[1]}": "{@param searchText}" } * } * ] * } * } * </pre> */ public static Query createMatchQuery(Set<String> fields, String searchText) { var bool = new BoolQuery.Builder(); fields.stream() .map(field -> { var matchQuery = new MatchQuery.Builder() .field(field) .query(searchText) .build(); return matchQuery._toQuery(); }) .forEach(bool::should); return bool.build()._toQuery(); }