# Stop search when ES finds N matches from a set of daily indices

**URL:** <https://discuss.elastic.co/t/stop-search-when-es-finds-n-matches-from-a-set-of-daily-indices/33119>\
**Category:** Elasticsearch\
**Created:** [October 28, 2015, 4:37am UTC](https://discuss.elastic.co/t/stop-search-when-es-finds-n-matches-from-a-set-of-daily-indices/33119 "2015-10-28T04:37:11Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![otisg](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/otisg/32/492_2.png) [@otisg](https://discuss.elastic.co/u/otisg)\
**Post date:** [October 28, 2015, 4:37am UTC](https://discuss.elastic.co/t/stop-search-when-es-finds-n-matches-from-a-set-of-daily-indices/33119/1 "2015-10-28T04:37:11Z")

</div>

Hi,

A typical ELK use case:

- daily indices
- need to get only the last N that match a query (i.e. sorting by time and matches most likely coming from the very latest/current index)

Is there any way to tell ES "search these indices, one by one, newest to oldest, and stop when you find N matches"

Of course, this can be done manually, outside ES, by running queries one by one, but since this is such a common ELK usage pattern I was wondering if there is anything in ES, or maybe planned for future versions of ES, that would make this possible without one having to run queries one by one.

## Thanks, Otis

Monitoring - Log Management - Alerting - Anomaly Detection  
Elasticsearch Consulting - Support - Training - [http://sematext.com/](http://sematext.com/)

---

<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, 11:42pm UTC](https://discuss.elastic.co/t/stop-search-when-es-finds-n-matches-from-a-set-of-daily-indices/33119/2 "2017-07-05T23:42:15Z")

</div>

Closed on July 5, 2017, 11:42pm UTC


