# Get elastic shards failure upon search query across multiple indices (while creating indices)

**URL:** <https://discuss.elastic.co/t/get-elastic-shards-failure-upon-search-query-across-multiple-indices-while-creating-indices/322935>\
**Category:** Elasticsearch\
**Created:** [January 11, 2023, 1:52pm UTC](https://discuss.elastic.co/t/get-elastic-shards-failure-upon-search-query-across-multiple-indices-while-creating-indices/322935 "2023-01-11T13:52:37Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![fesiqueira](https://avatars.discourse-cdn.com/v4/letter/f/f9ae1b/32.png) [@fesiqueira](https://discuss.elastic.co/u/fesiqueira)\
**Post date:** [January 11, 2023, 1:52pm UTC](https://discuss.elastic.co/t/get-elastic-shards-failure-upon-search-query-across-multiple-indices-while-creating-indices/322935/1 "2023-01-11T13:52:37Z")

</div>

I'm using Elastic 7.13.1. I create indices dynamically using a template based on the year of a timestamp field. So when I try to index a document with a timestamp for 2023-01-01 into index `index-2023` the index will be created via the template if missing. I create the index with 5 shards and default number of replicas.

I also query multiple indices at once using the wildcard index-\*. I use Go and the [github.com/olivere/elastic/v7](http://github.com/olivere/elastic/v7) (v7.0.32) client library.

I am running a test with a clean elastic setup (no indices created) that run a go routine to index one document per year (up to N years) and one go routine that searches for some documents (using the wildcard indices). I parse the result for shard failures and often get failures like:

`[{"index":"index-2023","reason":{"index":"index-2023","index_uuid":"HQU0FmsvSDuar08SUD9lwg","reason":"[d35c437ed6dc][192.168.10.11:9300][indices:data/read/search[phase/query]]","shard":"0","type":"no_shard_available_action_exception"}},{"shard":4,"index":"index-2023","reason":{"index":"index-2023","index_uuid":"HQU0FmsvSDuar08SUD9lwg","reason":null,"shard":"4","type":"no_shard_available_action_exception"}}] `

Suggesting to me that while searching the wildcard indices the new index is created by the template but not "yet" fully available. If my assumption is correct, is there a way to prevent such shard failure (e.g. wait that all shards are available before letting the newly created index available for searches)?

Is there something similiar to the `wait_for_active_shards` query parameter when using the `create index` API, but for index templates?

I was suggested to refresh the index after indexing into it and it works, or to create the indices beforehand, but I was wondering if there is any other way to "wait" the shards to be available.

Thank you!

---

<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 8, 2023, 1:53pm UTC](https://discuss.elastic.co/t/get-elastic-shards-failure-upon-search-query-across-multiple-indices-while-creating-indices/322935/2 "2023-02-08T13:53:34Z")

</div>

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