# Fetch all documents from index having max(field) \<= today's date

**URL:** <https://discuss.elastic.co/t/fetch-all-documents-from-index-having-max-field-todays-date/218844>\
**Category:** Elasticsearch\
**Created:** [February 11, 2020, 6:49pm UTC](https://discuss.elastic.co/t/fetch-all-documents-from-index-having-max-field-todays-date/218844 "2020-02-11T18:49:40Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![priteshshah17](https://avatars.discourse-cdn.com/v4/letter/p/8491ac/32.png) [@priteshshah17](https://discuss.elastic.co/u/priteshshah17)\
**Post date:** [February 11, 2020, 6:49pm UTC](https://discuss.elastic.co/t/fetch-all-documents-from-index-having-max-field-todays-date/218844/1 "2020-02-11T18:49:40Z")

</div>

I have a SQL query as below which is very simple when its SQL however I am not getting how to convert it to elastic query,  
Select \* from user A where A.field = (select max(C.field) from user C where C.table = A.table and C.field \<= sysdate) and A.field5 = 'A' and A.field2 = 'Y' and A.field3 = 'N' AND A.field4 IN ('A', 'B', 'C');

Any help is highly appreciated!

---

<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:** [March 10, 2020, 6:49pm UTC](https://discuss.elastic.co/t/fetch-all-documents-from-index-having-max-field-todays-date/218844/2 "2020-03-10T18:49:44Z")

</div>

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