Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[BUG] JsonException when SearchRequest contains a query of type range using .toJsonString function #1171

Open
mikeperello-scopely opened this issue Aug 29, 2024 · 3 comments
Labels
bug Something isn't working

Comments

@mikeperello-scopely
Copy link

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.

@mikeperello-scopely mikeperello-scopely added bug Something isn't working untriaged labels Aug 29, 2024
@matthias-koch
Copy link

I have this issue with all aggregation searches.

@dblock
Copy link
Member

dblock commented Sep 16, 2024

@mikeperello-scopely @matthias-koch Would one of you please care to help writing a (failing) unit test for this? Let's fix it.

@mikeperello-scopely
Copy link
Author

Sure, @dblock! Added.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
bug Something isn't working
Projects
None yet
Development

No branches or pull requests

3 participants