# Selecting the earliest hit for a specific field

**URL:** <https://discuss.elastic.co/t/selecting-the-earliest-hit-for-a-specific-field/57797>\
**Category:** Elasticsearch\
**Created:** [August 11, 2016, 10:57am UTC](https://discuss.elastic.co/t/selecting-the-earliest-hit-for-a-specific-field/57797 "2016-08-11T10:57:38Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![JeremyFelder](https://avatars.discourse-cdn.com/v4/letter/j/90ced4/32.png) [@JeremyFelder](https://discuss.elastic.co/u/JeremyFelder)\
**Post date:** [August 11, 2016, 10:57am UTC](https://discuss.elastic.co/t/selecting-the-earliest-hit-for-a-specific-field/57797/1 "2016-08-11T10:57:38Z")

</div>

Lets say I have 1000 Documents in an index each containing a field `name` and a field `reportDate`. I know I can aggregate against these fields to find the amount of Documents per unique `name` and I know I can sort them by date entered. What I can't figure out is how to get only the earliest entered document per unique `name`.

For Example; Lets say we had the following documents:

1. `{ name: Sam, reportDate: 2016-03-17 }`

2. `{ name: Sam, reportDate: 2016-03-13 }`

3. `{ name: Joe, reportDate: 2016-04-03 }`

4. `{ name: Joe, reportDate: 2016-05-19 }`

After the query I would want only Documents 2 and 3 to be hits; The earliest report per name.

Thanks,

Jeremy

---

<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:** [July 5, 2017, 10:28pm UTC](https://discuss.elastic.co/t/selecting-the-earliest-hit-for-a-specific-field/57797/2 "2017-07-05T22:28:27Z")

</div>


