# shardFailures in SearchResponse showing from previous query

**URL:** https://discuss.elastic.co/t/shardfailures-in-searchresponse-showing-from-previous-query/8616
**Category:** Elasticsearch
**Created:** [August 2, 2012, 11:06pm UTC](https://discuss.elastic.co/t/shardfailures-in-searchresponse-showing-from-previous-query/8616 "2012-08-02T23:06:47Z")
**Posts on this page:** 8
**Page:** 1

<div class="post-metadata">

### Author: ![Lar\_Mader](https://avatars.discourse-cdn.com/v4/letter/l/a6a055/32.png) [@Lar\_Mader](https://discuss.elastic.co/u/Lar_Mader)
#### Post date: [August 2, 2012, 11:06pm UTC](https://discuss.elastic.co/t/shardfailures-in-searchresponse-showing-from-previous-query/8616/1 "2012-08-02T23:06:47Z")

</div>

I am confused about how to interpret the SearchResponse.shardFailures  
array, as this is showing failures from a previous failed query in the  
SearchResponse from a new successful query, as follows:

1. First execute a query that fails, either due to malformed json in the  
query, or with correct json but a query that is invalid.
2. Then execute a new query that is correct and succeeds. The  
SearchResponse from this query has failedShards == 0, but the shardFailures  
array has items from the previous failed query.

So is this the correct behavior??  
And if so, how does one know which shardFailures are from the current query  
or a previous one. This becomes more of an issue I think when two queries  
fail in a row - in this case the SearchResponse from the second query has  
items in the shardFailures array from both queries.

Lar

---

<div class="post-metadata">

### Author: ![jprante](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jprante/32/44941_2.png) [@jprante](https://discuss.elastic.co/u/jprante)
#### Post date: [August 3, 2012, 11:39pm UTC](https://discuss.elastic.co/t/shardfailures-in-searchresponse-showing-from-previous-query/8616/2 "2012-08-03T23:39:27Z")

</div>

Hi,

are you using replica? The shard failures happen on all shards, but a  
response is generated by draining only from one replica set of shard.  
Clearing the exceptions will not occur on the other replica shard set. So  
the messages live on and they happen to get visible by a follow-up query,  
when shard addressing changes to some other replica set.

Try if the effect disappears when removing replica. I think it's a harmless  
glitch. Clients should check for HTTP status code for errors, or failed  
shard count, but not by examining shard failure exception messages in the  
first place.

Best regards,

Jörg

On Friday, August 3, 2012 1:06:47 AM UTC+2, lmader wrote:

> I am confused about how to interpret the SearchResponse.shardFailures  
> array, as this is showing failures from a previous failed query in the  
> SearchResponse from a new successful query, as follows:
> 
> 1. First execute a query that fails, either due to malformed json in the  
> query, or with correct json but a query that is invalid.
> 2. Then execute a new query that is correct and succeeds. The  
> SearchResponse from this query has failedShards == 0, but the shardFailures  
> array has items from the previous failed query.
> 
> So is this the correct behavior??  
> And if so, how does one know which shardFailures are from the current  
> query or a previous one. This becomes more of an issue I think when two  
> queries fail in a row - in this case the SearchResponse from the second  
> query has items in the shardFailures array from both queries.
> 
> Lar

---

<div class="post-metadata">

### Author: ![Lar\_Mader](https://avatars.discourse-cdn.com/v4/letter/l/a6a055/32.png) [@Lar\_Mader](https://discuss.elastic.co/u/Lar_Mader)
#### Post date: [August 6, 2012, 4:28pm UTC](https://discuss.elastic.co/t/shardfailures-in-searchresponse-showing-from-previous-query/8616/3 "2012-08-06T16:28:18Z")

</div>

Well, I am not using replica sets.

So it seems to me that this is a bug, although perhaps it would be  
considered minor. It seems incorrect for the SearchResponse to have  
exception messages in the shardFailures array when the shards didn't fail  
(in the result from the second query). This makes the shardFailures  
messages misleading and unreliable.

Or am I still missing something?

Thanks!  
Lar

On Fri, Aug 3, 2012 at 4:39 PM, Jörg Prante [joergprante@gmail.com](mailto:joergprante@gmail.com) wrote:

> Hi,
> 
> are you using replica? The shard failures happen on all shards, but a  
> response is generated by draining only from one replica set of shard.  
> Clearing the exceptions will not occur on the other replica shard set. So  
> the messages live on and they happen to get visible by a follow-up query,  
> when shard addressing changes to some other replica set.
> 
> Try if the effect disappears when removing replica. I think it's a  
> harmless glitch. Clients should check for HTTP status code for errors, or  
> failed shard count, but not by examining shard failure exception messages  
> in the first place.
> 
> Best regards,
> 
> Jörg
> 
> On Friday, August 3, 2012 1:06:47 AM UTC+2, lmader wrote:
> 
> > I am confused about how to interpret the SearchResponse.\*\*shardFailures  
> > array, as this is showing failures from a previous failed query in the  
> > SearchResponse from a new successful query, as follows:
> > 
> > 1. First execute a query that fails, either due to malformed json in the  
> > query, or with correct json but a query that is invalid.
> > 2. Then execute a new query that is correct and succeeds. The  
> > SearchResponse from this query has failedShards == 0, but the shardFailures  
> > array has items from the previous failed query.
> > 
> > So is this the correct behavior??  
> > And if so, how does one know which shardFailures are from the current  
> > query or a previous one. This becomes more of an issue I think when two  
> > queries fail in a row - in this case the SearchResponse from the second  
> > query has items in the shardFailures array from both queries.
> > 
> > Lar

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [August 7, 2012, 9:31pm UTC](https://discuss.elastic.co/t/shardfailures-in-searchresponse-showing-from-previous-query/8616/4 "2012-08-07T21:31:03Z")

</div>

If this is the case, its definitely a bug, can you maybe open an issue with a gist (curl) recreation? which version are you using?

On Aug 6, 2012, at 6:28 PM, Lar Mader [lmaderintrepid@gmail.com](mailto:lmaderintrepid@gmail.com) wrote:

> Well, I am not using replica sets.
> 
> So it seems to me that this is a bug, although perhaps it would be considered minor. It seems incorrect for the SearchResponse to have exception messages in the shardFailures array when the shards didn't fail (in the result from the second query). This makes the shardFailures messages misleading and unreliable.
> 
> Or am I still missing something?
> 
> Thanks!  
> Lar
> 
> On Fri, Aug 3, 2012 at 4:39 PM, Jörg Prante [joergprante@gmail.com](mailto:joergprante@gmail.com) wrote:  
> Hi,
> 
> are you using replica? The shard failures happen on all shards, but a response is generated by draining only from one replica set of shard. Clearing the exceptions will not occur on the other replica shard set. So the messages live on and they happen to get visible by a follow-up query, when shard addressing changes to some other replica set.
> 
> Try if the effect disappears when removing replica. I think it's a harmless glitch. Clients should check for HTTP status code for errors, or failed shard count, but not by examining shard failure exception messages in the first place.
> 
> Best regards,
> 
> Jörg
> 
> On Friday, August 3, 2012 1:06:47 AM UTC+2, lmader wrote:  
> I am confused about how to interpret the SearchResponse.shardFailures array, as this is showing failures from a previous failed query in the SearchResponse from a new successful query, as follows:
> 
> 1. First execute a query that fails, either due to malformed json in the query, or with correct json but a query that is invalid.
> 2. Then execute a new query that is correct and succeeds. The SearchResponse from this query has failedShards == 0, but the shardFailures array has items from the previous failed query.
> 
> So is this the correct behavior??  
> And if so, how does one know which shardFailures are from the current query or a previous one. This becomes more of an issue I think when two queries fail in a row - in this case the SearchResponse from the second query has items in the shardFailures array from both queries.
> 
> Lar

---

<div class="post-metadata">

### Author: ![Lar\_Mader](https://avatars.discourse-cdn.com/v4/letter/l/a6a055/32.png) [@Lar\_Mader](https://discuss.elastic.co/u/Lar_Mader)
#### Post date: [August 7, 2012, 11:34pm UTC](https://discuss.elastic.co/t/shardfailures-in-searchresponse-showing-from-previous-query/8616/5 "2012-08-07T23:34:57Z")

</div>

Ok, I opened an issue with a set of steps, as curl commands at:

> <https://github.com/elastic/elasticsearch/issues/2148>
>
> Steps to repro issue with the shardFailures array showing msgs from a previous (…not current) query:
> 
> 1) create something
> curl -XPUT localhost:9200/acme/blog/1111 -d '{"message":"foo"}'
> 
> 2) execute this query - it should succeed
> curl -XGET localhost:9200/acme/blog/\_search -d '{"query":{"field":{"message":"foo"}}}'
> 
> 3) this is an invalid query and is expected to fail
> curl -XGET localhost:9200/acme/blog/\_search -d '{"foobar":{"message":"foo"}}'
> 
> 4) now rerun the query from step 2. This query succeeds, and returns the hits, but also shows the shardFailures from the failed query in step 3
> curl -XGET localhost:9200/acme/blog/\_search -d '{"query":{"field":{"message":"foo"}}}'
> 
> Here is the output I get from step 4) :
> 
> {"took":3,"timed\_out":false,"\_shards":{"total":5,"successful":5,"failed":0,"failures":\[{"index":"acme","shard":1,"status":400,"reason":"SearchParseException\[\[acme\]\[1\]: from\[-1\],size\[-1\]: Parse Failure \[Failed to parse source \[{\\"foobar\\":{\\"message\\":\\"foo\\"}}\]\]\]; nested: SearchParseException\[\[acme\]\[1\]: from\[-1\],size\[-1\]: Parse Failure \[No parser for element \[foobar\]\]\]; "},{"index":"acme","shard":0,"status":400,"reason":"SearchParseException\[\[acme\]\[0\]: from\[-1\],size\[-1\]: Parse Failure \[Failed to parse source \[{\\"foobar\\":{\\"message\\":\\"foo\\"}}\]\]\]; nested: SearchParseException\[\[acme\]\[0\]: from\[-1\],size\[-1\]: Parse Failure \[No parser for element \[foobar\]\]\]; "},{"index":"acme","shard":4,"status":400,"reason":"SearchParseException\[\[acme\]\[4\]: from\[-1\],size\[-1\]: Parse Failure \[Failed to parse source \[{\\"foobar\\":{\\"message\\":\\"foo\\"}}\]\]\]; nested: SearchParseException\[\[acme\]\[4\]: from\[-1\],size\[-1\]: Parse Failure \[No parser for element \[foobar\]\]\]; "}\]},"hits":{"total":1,"max\_score":1.6931472,"hits":\[{"\_index":"acme","\_type":"blog","\_id":"1111","\_score":1.6931472, "\_source" : {"message" : "foo" }}\]}}

I am using elasticsearch version 0.18.7.

Cheers,  
Lar

On Tue, Aug 7, 2012 at 2:31 PM, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:

> If this is the case, its definitely a bug, can you maybe open an issue  
> with a gist (curl) recreation? which version are you using?
> 
> On Aug 6, 2012, at 6:28 PM, Lar Mader [lmaderintrepid@gmail.com](mailto:lmaderintrepid@gmail.com) wrote:
> 
> Well, I am not using replica sets.
> 
> So it seems to me that this is a bug, although perhaps it would be  
> considered minor. It seems incorrect for the SearchResponse to have  
> exception messages in the shardFailures array when the shards didn't fail  
> (in the result from the second query). This makes the shardFailures  
> messages misleading and unreliable.
> 
> Or am I still missing something?
> 
> Thanks!  
> Lar
> 
> On Fri, Aug 3, 2012 at 4:39 PM, Jörg Prante [joergprante@gmail.com](mailto:joergprante@gmail.com) wrote:
> 
> > Hi,
> > 
> > are you using replica? The shard failures happen on all shards, but a  
> > response is generated by draining only from one replica set of shard.  
> > Clearing the exceptions will not occur on the other replica shard set. So  
> > the messages live on and they happen to get visible by a follow-up query,  
> > when shard addressing changes to some other replica set.
> > 
> > Try if the effect disappears when removing replica. I think it's a  
> > harmless glitch. Clients should check for HTTP status code for errors, or  
> > failed shard count, but not by examining shard failure exception messages  
> > in the first place.
> > 
> > Best regards,
> > 
> > Jörg
> > 
> > On Friday, August 3, 2012 1:06:47 AM UTC+2, lmader wrote:
> > 
> > > I am confused about how to interpret the SearchResponse.\*\*shardFailures  
> > > array, as this is showing failures from a previous failed query in the  
> > > SearchResponse from a new successful query, as follows:
> > > 
> > > 1. First execute a query that fails, either due to malformed json in the  
> > > query, or with correct json but a query that is invalid.
> > > 2. Then execute a new query that is correct and succeeds. The  
> > > SearchResponse from this query has failedShards == 0, but the shardFailures  
> > > array has items from the previous failed query.
> > > 
> > > So is this the correct behavior??  
> > > And if so, how does one know which shardFailures are from the current  
> > > query or a previous one. This becomes more of an issue I think when two  
> > > queries fail in a row - in this case the SearchResponse from the second  
> > > query has items in the shardFailures array from both queries.
> > > 
> > > Lar

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [August 8, 2012, 9:49am UTC](https://discuss.elastic.co/t/shardfailures-in-searchresponse-showing-from-previous-query/8616/6 "2012-08-08T09:49:40Z")

</div>

This has been fixed in 0.19 (I just double checked your test case just in case).

On Aug 8, 2012, at 1:34 AM, Lar Mader [lmaderintrepid@gmail.com](mailto:lmaderintrepid@gmail.com) wrote:

> Ok, I opened an issue with a set of steps, as curl commands at:
> 
> [shardFailures in SearchResponse showing from previous query · Issue #2148 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/2148)
> 
> I am using elasticsearch version 0.18.7.
> 
> Cheers,  
> Lar
> 
> On Tue, Aug 7, 2012 at 2:31 PM, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:  
> If this is the case, its definitely a bug, can you maybe open an issue with a gist (curl) recreation? which version are you using?
> 
> On Aug 6, 2012, at 6:28 PM, Lar Mader [lmaderintrepid@gmail.com](mailto:lmaderintrepid@gmail.com) wrote:
> 
> > Well, I am not using replica sets.
> > 
> > So it seems to me that this is a bug, although perhaps it would be considered minor. It seems incorrect for the SearchResponse to have exception messages in the shardFailures array when the shards didn't fail (in the result from the second query). This makes the shardFailures messages misleading and unreliable.
> > 
> > Or am I still missing something?
> > 
> > Thanks!  
> > Lar
> > 
> > On Fri, Aug 3, 2012 at 4:39 PM, Jörg Prante [joergprante@gmail.com](mailto:joergprante@gmail.com) wrote:  
> > Hi,
> > 
> > are you using replica? The shard failures happen on all shards, but a response is generated by draining only from one replica set of shard. Clearing the exceptions will not occur on the other replica shard set. So the messages live on and they happen to get visible by a follow-up query, when shard addressing changes to some other replica set.
> > 
> > Try if the effect disappears when removing replica. I think it's a harmless glitch. Clients should check for HTTP status code for errors, or failed shard count, but not by examining shard failure exception messages in the first place.
> > 
> > Best regards,
> > 
> > Jörg
> > 
> > On Friday, August 3, 2012 1:06:47 AM UTC+2, lmader wrote:  
> > I am confused about how to interpret the SearchResponse.shardFailures array, as this is showing failures from a previous failed query in the SearchResponse from a new successful query, as follows:
> > 
> > 1. First execute a query that fails, either due to malformed json in the query, or with correct json but a query that is invalid.
> > 2. Then execute a new query that is correct and succeeds. The SearchResponse from this query has failedShards == 0, but the shardFailures array has items from the previous failed query.
> > 
> > So is this the correct behavior??  
> > And if so, how does one know which shardFailures are from the current query or a previous one. This becomes more of an issue I think when two queries fail in a row - in this case the SearchResponse from the second query has items in the shardFailures array from both queries.
> > 
> > Lar

---

<div class="post-metadata">

### Author: ![Lar\_Mader](https://avatars.discourse-cdn.com/v4/letter/l/a6a055/32.png) [@Lar\_Mader](https://discuss.elastic.co/u/Lar_Mader)
#### Post date: [August 8, 2012, 5:33pm UTC](https://discuss.elastic.co/t/shardfailures-in-searchresponse-showing-from-previous-query/8616/7 "2012-08-08T17:33:38Z")

</div>

Ah, you are correct sir, this is indeed fixed in 0.19. Thanks!!  
Lar

On Wed, Aug 8, 2012 at 2:49 AM, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:

> This has been fixed in 0.19 (I just double checked your test case just in  
> case).
> 
> On Aug 8, 2012, at 1:34 AM, Lar Mader [lmaderintrepid@gmail.com](mailto:lmaderintrepid@gmail.com) wrote:
> 
> Ok, I opened an issue with a set of steps, as curl commands at:
> 
> [shardFailures in SearchResponse showing from previous query · Issue #2148 · elastic/elasticsearch · GitHub](https://github.com/elasticsearch/elasticsearch/issues/2148)
> 
> I am using elasticsearch version 0.18.7.
> 
> Cheers,  
> Lar
> 
> On Tue, Aug 7, 2012 at 2:31 PM, Shay Banon [kimchy@gmail.com](mailto:kimchy@gmail.com) wrote:
> 
> > If this is the case, its definitely a bug, can you maybe open an issue  
> > with a gist (curl) recreation? which version are you using?
> > 
> > On Aug 6, 2012, at 6:28 PM, Lar Mader [lmaderintrepid@gmail.com](mailto:lmaderintrepid@gmail.com) wrote:
> > 
> > Well, I am not using replica sets.
> > 
> > So it seems to me that this is a bug, although perhaps it would be  
> > considered minor. It seems incorrect for the SearchResponse to have  
> > exception messages in the shardFailures array when the shards didn't fail  
> > (in the result from the second query). This makes the shardFailures  
> > messages misleading and unreliable.
> > 
> > Or am I still missing something?
> > 
> > Thanks!  
> > Lar
> > 
> > On Fri, Aug 3, 2012 at 4:39 PM, Jörg Prante [joergprante@gmail.com](mailto:joergprante@gmail.com)wrote:
> > 
> > > Hi,
> > > 
> > > are you using replica? The shard failures happen on all shards, but a  
> > > response is generated by draining only from one replica set of shard.  
> > > Clearing the exceptions will not occur on the other replica shard set. So  
> > > the messages live on and they happen to get visible by a follow-up query,  
> > > when shard addressing changes to some other replica set.
> > > 
> > > Try if the effect disappears when removing replica. I think it's a  
> > > harmless glitch. Clients should check for HTTP status code for errors, or  
> > > failed shard count, but not by examining shard failure exception messages  
> > > in the first place.
> > > 
> > > Best regards,
> > > 
> > > Jörg
> > > 
> > > On Friday, August 3, 2012 1:06:47 AM UTC+2, lmader wrote:
> > > 
> > > > I am confused about how to interpret the SearchResponse.\*\*shardFailures  
> > > > array, as this is showing failures from a previous failed query in the  
> > > > SearchResponse from a new successful query, as follows:
> > > > 
> > > > 1. First execute a query that fails, either due to malformed json in  
> > > > the query, or with correct json but a query that is invalid.
> > > > 2. Then execute a new query that is correct and succeeds. The  
> > > > SearchResponse from this query has failedShards == 0, but the shardFailures  
> > > > array has items from the previous failed query.
> > > > 
> > > > So is this the correct behavior??  
> > > > And if so, how does one know which shardFailures are from the current  
> > > > query or a previous one. This becomes more of an issue I think when two  
> > > > queries fail in a row - in this case the SearchResponse from the second  
> > > > query has items in the shardFailures array from both queries.
> > > > 
> > > > Lar

---

<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 6, 2017, 3:17am UTC](https://discuss.elastic.co/t/shardfailures-in-searchresponse-showing-from-previous-query/8616/8 "2017-07-06T03:17:04Z")

</div>


