# How to distribute search requests by date

**URL:** <https://discuss.elastic.co/t/how-to-distribute-search-requests-by-date/262405>\
**Category:** Elasticsearch\
**Created:** [January 27, 2021, 6:18pm UTC](https://discuss.elastic.co/t/how-to-distribute-search-requests-by-date/262405 "2021-01-27T18:18:13Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![ozgun](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ozgun/32/83011_2.png) [@ozgun](https://discuss.elastic.co/u/ozgun)\
**Post date:** [January 27, 2021, 6:18pm UTC](https://discuss.elastic.co/t/how-to-distribute-search-requests-by-date/262405/1 "2021-01-27T18:18:13Z")

</div>

Hello,

I have daily indexes in the format of "payments-2021-01-27". When I search documents I send a time based query and I want to distribute search requests to the matched indexes by date.

For example when I search last one month records I only want to search data in last one month's indexes. I shouldn't search documents in older indexes. Is there a method to achieve this?

(Btw, I'm developing with .NET Core and using NEST)

Thank you.

---

<div class="post-metadata">

**Author:** ![Jaspreet\_Singh](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jaspreet_singh/32/58296_2.png) [@Jaspreet\_Singh](https://discuss.elastic.co/u/Jaspreet_Singh)\
**Post date:** [January 27, 2021, 7:13pm UTC](https://discuss.elastic.co/t/how-to-distribute-search-requests-by-date/262405/2 "2021-01-27T19:13:39Z")

</div>

msearch ([https://www.elastic.co/guide/en/elasticsearch/reference/current/search-multi-search.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/search-multi-search.html)) feature should be able to help.  
One way you could do it is ...  
GET /\_msearch  
{"index": index\_1}  
{"query":...}  
GET /\_msearch  
{"index": index\_2}  
{"query":...}

where you can programmatically generated patterns for index\_1 and index 2 etc. to be what you want.  
Hope this helps

---

<div class="post-metadata">

**Author:** ![DavidTurner](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/davidturner/32/22453_2.png) [@DavidTurner](https://discuss.elastic.co/u/DavidTurner)\
**Post date:** [January 27, 2021, 8:54pm UTC](https://discuss.elastic.co/t/how-to-distribute-search-requests-by-date/262405/3 "2021-01-27T20:54:27Z")

</div>

Typically you should just search all the indices and let Elasticsearch determine which ones to skip. If your query contains a filter by a date range then it's automatically optimised up-front into a `MatchNoDocsQuery` on every shard whose date range doesn't overlap the range in the query. A `MatchNoDocsQuery` is rather easy to execute 🙂

---

<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:** [February 24, 2021, 8:54pm UTC](https://discuss.elastic.co/t/how-to-distribute-search-requests-by-date/262405/4 "2021-02-24T20:54:32Z")

</div>

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