0
votes

I have an Index in Elasticsearch with one document we can say doc id 01 and I updated the document with new doc ID we can say id 02 now I have two documents.

My Question is I want only one latest document(which is doc id 02) in search query(index/_search) what will be the query for such type of scenario.

1

1 Answers

0
votes

If you want to get the document having the maximum value (assuming you are creating doc_id in increase numerical order from the example given) for doc_id, you can use this query:

curl "https://{es_endpoint}/sample_index/_search?pretty" -H 'Content-Type: application/json' -d'
{
  "sort" : [
    { "_id" : {"order" : "desc"}}
  ],
  "size": 1
}'