Aggregates on collapse

New user looking for help, I know that aggregates don't work on the collapse results but I can't seem to find a way to achieve the same affect directly. We have a relatively simple dataset that contains multiple entries for the same key 'referencenumber' and I want to build a set of counts for the final 'status' of each 'referencenumber'. So if they did work together it would look like;

GET indexname*/_search
{
  "query": {
    "bool": {
      "must": [
        {
          "range": {
            "createddate": {
              "gte": "2020-12-01",
              "lte": "2020-12-15"
            }
          }
        }
      ]
    }
  },
  "collapse": {
    "field": "referencenumber",
    "inner_hits": {
      "name": "most_recent",
      "size": 1,
      "sort": [
        {
          "timestamp": "desc"
        }
      ]
    }
  },
  "aggs": {
    "JourneyResults": {
      "terms": {
        "field": "journeyresult.status"
      }
    }
  }
}

Is there a way to do this only using aggs?

2 Likes

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