Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How can I get last arrived document ElasticSearch?

I have a cluster with documents that contains timestamp field.

How can i request for the last arrived of them?

like image 549
Smasell Avatar asked Dec 25 '22 18:12

Smasell


1 Answers

A query like the one below should do the trick. It'll get you the one document with the latest date in the timestamp field.

{
  "size": 1,
  "query": {
    "match_all": {}
  },
  "sort": {
    "timestamp": "desc"
  }
}
like image 128
Val Avatar answered Jan 02 '23 08:01

Val