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

New 8.15.0 query using date_histogram throw [es/search] failed: [x_content_parse_exception] [1:391] [bool] failed to parse field [must] #864

Closed
cruzfernandoh opened this issue Aug 16, 2024 · 3 comments · Fixed by #868
Labels
Area: Generator Category: Bug Something isn't working

Comments

@cruzfernandoh
Copy link

cruzfernandoh commented Aug 16, 2024

Java API client version

8.15.0

Java version

21.0.3

Elasticsearch Version

8.15.0

Problem description

Hi there,

I have a query that works perfectly in Elastic 8.13.1, but now I receive the following error:

[es/search] failed: [x_content_parse_exception] [1:391] [bool] failed to parse field [must]

However, when I print my query in the terminal and execute it in the Elastic Dev Tools, it works fine:

{ "query": { "bool": { "must": [ { "range": { "@timestamp": { "gte": "2024-08-13 21:07:00", "lte": "2024-08-16 21:07:00", "format": "yyyy-MM-dd HH:mm:ss" } } }, { "term": { "station_id": {my_station_id} } }, { "nested": { "path": {path}, "query": { "bool": { "must": [ { "exists": { "field": {field} } } ] } } } } ] } }, "size": 0, "aggs": { "station": { "date_histogram": { "field": "@timestamp", "fixed_interval": "1h", "min_doc_count": 1 }, "aggs": { "nested": { "nested": { "path": {path} }, "aggs": { "value": { "avg": { "field": {field} } } } } } } } }

What's strange is that I use the same query with different aggregations (aggs) max, min, and avg values work fine. But when I try to use the date_histogram aggregation, this error occurs.

I'd be happy to provide further details where needed or a full request example. Thanks in advance.

@l-trotta
Copy link
Contributor

Hello! Yes please a full request would make this much easier to reproduce, thank you.

@cruzfernandoh
Copy link
Author

I have a template where I insert values, and it generates the following JSON:
{ "query":{ "bool":{ "must":[ { "range":{ "@timestamp":{ "gte":"2024-08-13 21:07:00", "lte":"2024-08-16 21:07:00", "format":"yyyy-MM-dd HH:mm:ss" } } }, { "term":{ "station_id":"my_station_id" } }, { "nested":{ "path":"path", "query":{ "bool":{ "must":[ { "exists":{ "field":"my_field" } } ] } } } } ] } }, "size":0, "aggs":{ "station":{ "date_histogram":{ "field":"@timestamp", "fixed_interval":"1h", "min_doc_count":1 }, "aggs":{ "nested":{ "nested":{ "path":"path" }, "aggs":{ "value":{ "avg":{ "field":"my_field" } } } } } } } }

I then use the following method to execute that search via elastic client:

SearchResponse<Void> response = client.search( builder -> builder .index( index ) .withJson( new StringReader( query ) ), Void.class );

@l-trotta
Copy link
Contributor

Thank for the example! This is related to #863, there's currently a bug with the serialization of the DateRangeQuery which is affecting queries that include it as well. It will be fixed in the next patch, sorry for the inconvenience.

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

Successfully merging a pull request may close this issue.

2 participants