# Query for document with least value

**URL:** <https://discuss.elastic.co/t/query-for-document-with-least-value/158558>\
**Category:** Elasticsearch\
**Created:** [November 28, 2018, 11:55am UTC](https://discuss.elastic.co/t/query-for-document-with-least-value/158558 "2018-11-28T11:55:19Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Ruthvik\_Sai](https://avatars.discourse-cdn.com/v4/letter/r/a587f6/32.png) [@Ruthvik\_Sai](https://discuss.elastic.co/u/Ruthvik_Sai)\
**Post date:** [November 28, 2018, 11:55am UTC](https://discuss.elastic.co/t/query-for-document-with-least-value/158558/1 "2018-11-28T11:55:20Z")

</div>

Hi,  
How can I write a query such that I get the document with the least value of a particular field?  
For ex: I have a "marks" field. how do I get the document having the least value of marks

Now if I extend the same thing how can I get the doc which was first created (least value of date stamp)...

Thanks

---

<div class="post-metadata">

**Author:** ![zz\_hello](https://avatars.discourse-cdn.com/v4/letter/z/3bc359/32.png) [@zz\_hello](https://discuss.elastic.co/u/zz_hello)\
**Post date:** [November 29, 2018, 6:13am UTC](https://discuss.elastic.co/t/query-for-document-with-least-value/158558/2 "2018-11-29T06:13:18Z")

</div>

you can use aggregation

---

<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:** [December 27, 2018, 6:13am UTC](https://discuss.elastic.co/t/query-for-document-with-least-value/158558/3 "2018-12-27T06:13:21Z")

</div>

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