I was trying to build from here:
But I didn't get anywhere. Because this way the results I get are from all documents that match 'foo' = 'bar', an array of buckets for each value of 'some_field'. And the buckets only give me the possible values of 'some_field' and the document count. For each bucket I want to get the whole document with the most recent timestamp, i.e., order by timestamp desc, and limiting to 1 document per possible value of 'some_field'.
Is aggregations the best way to get this? It seems I only get the document count with the buckets. Is there any other approach that might be better to do this?