# How Can i get max id of indexed documents

**URL:** <https://discuss.elastic.co/t/how-can-i-get-max-id-of-indexed-documents/110403>\
**Category:** Elasticsearch\
**Created:** [December 5, 2017, 6:05pm UTC](https://discuss.elastic.co/t/how-can-i-get-max-id-of-indexed-documents/110403 "2017-12-05T18:05:18Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![pamara](https://avatars.discourse-cdn.com/v4/letter/p/958977/32.png) [@pamara](https://discuss.elastic.co/u/pamara)\
**Post date:** [December 5, 2017, 6:05pm UTC](https://discuss.elastic.co/t/how-can-i-get-max-id-of-indexed-documents/110403/1 "2017-12-05T18:05:18Z")

</div>

I am new to elastic search. I indexed few of documents and i want to find the max id which ever inserted across the documents.

My URL something like ":/books/dramabooks/\_search?size=0"  
{  
"aggs" : {  
"max\_id" : { "max" : { "field" : "id" } }  
}  
} --POST URL

Response:  
{"took":75,"timed\_out":false,"\_shards":{"total":5,"successful":5,"failed":0},"hits":{"total":5,"max\_score":0.0,"hits":[]},"aggregations":{"max\_id":{"value":null}}}

Note:request returning max\_id value as null.

Could you please provide right query that should return maximum value of id.

Thanks in advance.

---

<div class="post-metadata">

**Author:** ![mujtabahussain](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mujtabahussain/32/17514_2.png) [@mujtabahussain](https://discuss.elastic.co/u/mujtabahussain)\
**Post date:** [December 5, 2017, 11:25pm UTC](https://discuss.elastic.co/t/how-can-i-get-max-id-of-indexed-documents/110403/2 "2017-12-05T23:25:16Z")

</div>

Hey!

ID's are usually a SHA or UUID! There is no pattern of numerical ascendancy/descendancy to them to find out the max of, unless you are overriding the ID upon insertion!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [January 2, 2018, 11:25pm UTC](https://discuss.elastic.co/t/how-can-i-get-max-id-of-indexed-documents/110403/3 "2018-01-02T23:25:26Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
