# Search to only return when all shards are successful

**URL:** <https://discuss.elastic.co/t/search-to-only-return-when-all-shards-are-successful/106922>\
**Category:** Elasticsearch\
**Created:** [November 8, 2017, 6:51pm UTC](https://discuss.elastic.co/t/search-to-only-return-when-all-shards-are-successful/106922 "2017-11-08T18:51:50Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![gansvv](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gansvv/32/23904_2.png) [@gansvv](https://discuss.elastic.co/u/gansvv)\
**Post date:** [November 8, 2017, 6:51pm UTC](https://discuss.elastic.co/t/search-to-only-return-when-all-shards-are-successful/106922/1 "2017-11-08T18:51:50Z")

</div>

I am using ES 5.5 and prepareSearch.get to search for results.

[https://www.elastic.co/guide/en/elasticsearch/reference/5.5/search.html](https://www.elastic.co/guide/en/elasticsearch/reference/5.5/search.html)

The search API call in ES returns data on successful and failed shards, but the transport client does not return this in the response. Is there a way to get these stats with each prepareSearch call?

Also, is there a way to fail search requests when there are failed shards?

---

<div class="post-metadata">

**Author:** ![gansvv](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gansvv/32/23904_2.png) [@gansvv](https://discuss.elastic.co/u/gansvv)\
**Post date:** [November 8, 2017, 7:10pm UTC](https://discuss.elastic.co/t/search-to-only-return-when-all-shards-are-successful/106922/2 "2017-11-08T19:10:54Z")

</div>

I got the answer for the second question. The searchResponse from transport client has getFailedShards() as int.

---

<div class="post-metadata">

**Author:** ![gansvv](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/gansvv/32/23904_2.png) [@gansvv](https://discuss.elastic.co/u/gansvv)\
**Post date:** [November 8, 2017, 7:12pm UTC](https://discuss.elastic.co/t/search-to-only-return-when-all-shards-are-successful/106922/3 "2017-11-08T19:12:06Z")

</div>

So, I can add a check for failed shards and if so fail this search response and retry again later. But is there a server config for this?

---

<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:** [December 6, 2017, 7:12pm UTC](https://discuss.elastic.co/t/search-to-only-return-when-all-shards-are-successful/106922/4 "2017-12-06T19:12:08Z")

</div>

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