Document count after metric aggregation


I have a document representing of event on activity. This document is defined by

  • activity id
  • creation date of event
  • event type
  • message

I have to count the number of events per type but only on the last event for each activity id. I have to keep all events in the index for other purposes.

I know how to retrieve the last document from each id activity with a "top-hit" aggregation. I can count the number of documents by type of events. but I can not make the connection between these two requests.

Is there a way to link these two queries ? Should we create an index containing the latest events of each activity at the insertion of an new event ? Or is there another way to achieve the result?

Thanks for you help

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