Elasticsearch 8.5 scenarios to Aggregate on Nested Fields with Date Ranges
I'm converting an old project and I keep running into I'm relatively new to this, so bear with me. I'm sure I'm missing something obvious here, but I'm currently working with Elasticsearch 8.5 and working with an scenario when trying to aggregate data on a nested field that contains date ranges. I have a document structure that looks something like this: ```json { "user": "john_doe", "events": [ { "event_name": "start", "event_date": "2023-09-01T12:00:00Z" }, { "event_name": "end", "event_date": "2023-09-15T12:00:00Z" } ] } ``` I want to create an aggregation to count the number of events that occurred within a specific date range. My aggregation query looks like this: ```json { "query": { "match_all": {} }, "aggs": { "events_in_range": { "nested": { "path": "events" }, "aggs": { "date_filter": { "filter": { "range": { "events.event_date": { "gte": "2023-09-01", "lte": "2023-09-10" } } }, "aggs": { "event_count": { "value_count": { "field": "events.event_name" } } } } } } } } ``` However, when I run this query, I get the following behavior message: ``` "reason": "Field [events.event_date] not found in mapping; " ``` I've confirmed that `event_date` is present in the mappings for the nested field. I even tried explicitly defining the mapping for the nested field like so: ```json { "mappings": { "properties": { "events": { "type": "nested", "properties": { "event_name": { "type": "text" }, "event_date": { "type": "date" } } } } } } ``` I've also checked that there are events within the specified date range, but I still want to get the aggregation to work correctly. Has anyone faced a similar scenario or can provide insights on how to resolve this? Any help would be greatly appreciated. This is part of a larger application I'm building. For context: I'm using Json on Ubuntu. What's the best practice here? I'm open to any suggestions.