How to distribute search requests by date


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.

msearch ( feature should be able to help.
One way you could do it is ...
GET /_msearch
{"index": index_1}
GET /_msearch
{"index": index_2}

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

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 :slight_smile:

1 Like

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