What's the fastest manner to retrieve min timestamp from Elasticsearch indices?

487 views Asked by At

In my opinion, there are two ways to implement it. But I don't know which is faster, because I don't have much data to test.

Like SQL below:

SELECT min(occur_time) FROM event_*
SELECT occur_time FROM event_* order by occur_time limit 1
1

There are 1 answers

0
Opster Elasticsearch Expert On

You can run a query, with size:1, sorted by @timestamp ascending, and even include_fields:@timestamp in order to fetch back only the minimum timestamp field:

{
   "size":1,
   "sort": [{"@timestamp":"asc"}],
   "_source": {
         "includes": [ "@timestamp" ]
   }
 }