Aggregating child documents in has_child query

I would like to aggregate data from child documents in has_child query as well. The reason is, my child documents have the timestamp and when I aggregate the parent documents, I want to the first occurance and the last occurance of the parent in the child documents, within the time range that I query.

I found a this question already posted, but in 2011. Is there any new recommended method to do this?

One option I’m using now is to get the "field":"date" in the inner_hits and then sort it, with a size of 1.

      "inner_hits": {
        "fields": "date",
        "name": "date_sort",
        "size": 1,
        "sort": [
            "date": {
              "order": "desc"

By doing so, I’m able to get the last occurance, but not the first occurance.

Two questions:

  1. What I’m doing, is that the best method, if I have to use only inner_hits?
  2. Is there any other better method, other than inner_hits