Schema design and query - aggregation within nested document

I have a simple schema with a nested field. A sample product document look like this:

  "name": "product name",
  "events": [
      "startDate": "2021-01-01 00:00:00",
      "endDate": "2021-01-01 00:00:00",
      "price": 1.5
      "startDate": "2021-02-01 00:00:00",
      "endDate": "2021-02-01 00:00:00",
      "price": 2.5
   // more events ...

The "events" field is a nested document type. Let's say we have 10 millions documents in the Elasticsearch database, and I want to run aggregation only for the events occur on 2021-01-05. How would one write such query?

For clarification: the ask is to aggregate prices among all the products where events occur on 2021-01-05.

I googled "inner hits aggregation." Apparently "inner hits" does support aggregation and it's slow.

Why not indexing individual events instead of updating everytime the same document?

1 Like

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.