Elasticsearch 8.5 Fails to Return Expected Results with Date Range Queries on Nested Objects
I am experiencing an issue with Elasticsearch 8.5 where my date range queries on nested objects are not returning the expected results. I have a document structure that includes nested objects for event logs, and I need to filter these logs based on a date range. Hereโs a simplified example of my mappings: ```json { "mappings": { "properties": { "user_id": { "type": "keyword" }, "events": { "type": "nested", "properties": { "event_timestamp": { "type": "date" }, "event_type": { "type": "keyword" } } } } } } ``` I am running a query like this to find all `event_type` "login" events within a specific date range: ```json { "query": { "nested": { "path": "events", "query": { "bool": { "must": [ { "match": { "events.event_type": "login" } }, { "range": { "events.event_timestamp": { "gte": "2023-01-01T00:00:00Z", "lte": "2023-12-31T23:59:59Z" } } } ] } } } } } ``` However, I am getting results that donโt match the specified date range. For instance, I have events dated in 2022 that are appearing in the results. Iโve verified that my documents are indexed correctly. I have also tried restructuring my query to use a different combination of `must` and `filter`, but the outcome remains the same. Iโve included a sample document below for reference: ```json { "user_id": "12345", "events": [ { "event_timestamp": "2022-06-15T14:00:00Z", "event_type": "login" }, { "event_timestamp": "2023-05-20T09:00:00Z", "event_type": "login" } ] } ``` I would appreciate any insights on why the date filtering is not functioning as expected with nested queries or any best practices for querying nested objects with date fields. Are there any known issues with date range queries on nested fields in Elasticsearch 8.5?