[BUG] JsonException when SearchRequest contains a query of type range using .toJsonString function
What is the bug?
The .toJsonString function throws a JsonException when a SearchRequest includes a query of type range.
Specifically, it shows the following error:
Cannot find a serializer for type <type>. Consider using a full-featured JsonpMapper.
How can one reproduce the bug?
# Create a Query of type range
Query rangeQuery = Query.of(q -> q.range(r -> r
.field("time")
.format("strict_date_optional_time")
.gte(JsonData.of("2024-06-29T09:50:53Z"))
.lte(JsonData.of("2024-06-29T10:50:53Z"))));
# Add it as part of a boolQuery
BoolQuery boolQuery = BoolQuery.of(b -> b
.filter(rangeQuery));
# Add the boolQuery to the SearchRequest
SearchRequest searchRequest = new SearchRequest.Builder()
.query(q -> q.bool(boolQuery))
.build();
# Execute the toJsonString()
System.out.println("query: " + searchRequest.toJsonString());
What is the expected behavior?
The query should print without any issues.
Do you have any additional context?
Other types of query, such as matchPhrase seem to work correctly. However, when adding a query of type range, it throws the error.
I have been investigating the error, and it looks it's related to the parsing of the gte and lte elements. Although they are declared as JsonData types, the value is extracted as String (in this case), leading to the JsonException.
This, however, does not seem to affect the SearchRequest functionality, as I have been able to query sucessfully.
I have this issue with all aggregation searches.
@mikeperello-scopely @matthias-koch Would one of you please care to help writing a (failing) unit test for this? Let's fix it.
Sure, @dblock! Added.
The fix for this was released in v2.19.0 of the client