Source:
private QueryBuilder buildTermQuery(BoolQueryBuilder queryBuilder, String columnName, Domain domain, Type type) { for (Range range : domain.getValues().getRanges().getOrderedRanges()) { BoolQueryBuilder rangeQueryBuilder = new BoolQueryBuilder(); Set<Object> valuesToInclude = new HashSet<>(); Set<Object> valuesToExclude = new HashSet<>(); checkState(!range.isAll(), "Invalid domain range: All for column: " + columnName); if (range.isSingleValue()) { valuesToInclude.add(range.getLow().getValue()); } else { if (!range.getLow().isLowerUnbounded()) { switch (range.getLow().getBound()) { case ABOVE: rangeQueryBuilder.must(new RangeQueryBuilder(columnName).gt(getValue(type, range.getLow().getValue()))); break; case EXACTLY: rangeQueryBuilder.must(new RangeQueryBuilder(columnName).gte(getValue(type, range.getLow().getValue()))); break; case BELOW: throw new IllegalArgumentException("Low marker should never use BELOW bound"); default: throw new AssertionError("Unhandled bound: " + range.getLow().getBound()); } } if (!range.getHigh().isUpperUnbounded()) { switch (range.getHigh().getBound()) { case EXACTLY: rangeQueryBuilder.must(new RangeQueryBuilder(columnName).lte(getValue(type, range.getHigh().getValue()))); break; case BELOW: rangeQueryBuilder.must(new RangeQueryBuilder(columnName).lt(getValue(type, range.getHigh().getValue()))); break; case ABOVE: throw new IllegalArgumentException("High marker should never use ABOVE bound"); default: throw new AssertionError("Unhandled bound: " + range.getHigh().getBound()); } } } for (Object value : valuesToExclude) { rangeQueryBuilder.mustNot(new TermQueryBuilder(columnName, getValue(type, value))); } if (valuesToInclude.size() == 1) { rangeQueryBuilder.must(new TermQueryBuilder(columnName, getValue(type, getOnlyElement(valuesToInclude)))); } queryBuilder.should(rangeQueryBuilder); } return queryBuilder; }

Target:
private QueryBuilder buildTermQuery(BoolQueryBuilder queryBuilder, String columnName, Domain domain, Type type) { for (Range range : domain.getValues().getRanges().getOrderedRanges()) { BoolQueryBuilder rangeQueryBuilder = new BoolQueryBuilder(); Set<Object> valuesToInclude = new HashSet<>(); checkState(!range.isAll(), "Invalid range for column:: " + columnName); if (range.isSingleValue()) { valuesToInclude.add(range.getLow().getValue()); } else { if (!range.getLow().isLowerUnbounded()) { switch (range.getLow().getBound()) { case ABOVE: rangeQueryBuilder.must(new RangeQueryBuilder(columnName).gt(getValue(type, range.getLow().getValue()))); break; case EXACTLY: rangeQueryBuilder.must(new RangeQueryBuilder(columnName).gte(getValue(type, range.getLow().getValue()))); break; case BELOW: throw new IllegalArgumentException("Low marker should never use BELOW bound"); default: throw new AssertionError("Unhandled bound: " + range.getLow().getBound()); } } if (!range.getHigh().isUpperUnbounded()) { switch (range.getHigh().getBound()) { case EXACTLY: rangeQueryBuilder.must(new RangeQueryBuilder(columnName).lte(getValue(type, range.getHigh().getValue()))); break; case BELOW: rangeQueryBuilder.must(new RangeQueryBuilder(columnName).lt(getValue(type, range.getHigh().getValue()))); break; case ABOVE: throw new IllegalArgumentException("High marker should never use ABOVE bound"); default: throw new AssertionError("Unhandled bound: " + range.getHigh().getBound()); } } } if (valuesToInclude.size() == 1) { rangeQueryBuilder.must(new TermQueryBuilder(columnName, getValue(type, getOnlyElement(valuesToInclude)))); } queryBuilder.should(rangeQueryBuilder); } return queryBuilder; }