Java Api Client RangeQueryBuilder has JsonData as an attribute for gte etc

I am trying to migrate my java application to use new java api client.
Today I realized that RangeQUeryBuildar has these strange types for gte, lte, etc methods.
Why is it JsonData type?

I am using Elasticsearch-java-7.16.2 version


1 Like

Range query accepts a number of different types such as string, numbers, date, date math, etc. The Java API client doesn't yet support all these types, and these values have been implemented as raw json data.

This will be improved in a future release. In the meantime, you can pass e.g. a string value (also works for other primitive types) as:

RangeQuery rq = RangeQuery.of(q ->"foo")));

Hope this helps.


I am using the version 7.15.2 and couldn't figure out how to use RangeQueryBuilder. Currently I am creating a JsonValue object and passing it to Query.Builder 's range method as below:

        final String json = "{ \"fld_date\": {\"gte\": \"2018-02-02T15:08:28Z\", \"lte\": \"2021-06-19T16:03:01.130Z\"}}";
        final JsonpMapper mapper = new JsonbJsonpMapper();
        final JsonParser parser = mapper.jsonProvider().createParser(new StringReader(json));
        final JsonData data = JsonData.from(parser, mapper);
        final JsonValue value = data.toJson(mapper);
 Query.Builder rangeBuilder = new Query.Builder();
rangeBuilder.range(value );

See the post:

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.