@Override
    ObjectNode toJson(ObjectMapper mapper) {
      if (lt == null && gt == null) {
        throw new IllegalStateException("Either lower or upper bound should be provided");
      }

      final ObjectNode result = mapper.createObjectNode();
      final ObjectNode range = result.with("range").with(fieldName);
      if (gt != null) {
        final String op = gte ? "gte" : "gt";
        range.set(op, toJsonValue(gt, mapper));
      }

      if (lt != null) {
        final String op = lte ? "lte" : "lt";
        range.set(op, toJsonValue(lt, mapper));
      }

      if (format != null) {
        range.put("format", format);
      }

      return result;
    }
A Query that matches documents within an range of terms.
criteria/elasticsearch/src/org/immutables/criteria/elasticsearch/QueryBuilders.java