Troubles to apply aggregation on search

I'm working with a stock entity and it's updated every 30 minutes. So I'm loading on elastic every modification of stock entity.

With this information I can create a stocklevel view but when I try to create the last state for each stock level I'm facing some issues. I tried to use the aggregation on search level (but seems not work).

Any clue?