# Error handling in rest api

**URL:** <https://discuss.elastic.co/t/error-handling-in-rest-api/15213>\
**Category:** Elasticsearch\
**Created:** [January 12, 2014, 2:51pm UTC](https://discuss.elastic.co/t/error-handling-in-rest-api/15213 "2014-01-12T14:51:29Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jettro\_Coenradie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jettro_coenradie/32/59704_2.png) [@Jettro\_Coenradie](https://discuss.elastic.co/u/Jettro_Coenradie)\
**Post date:** [January 12, 2014, 2:51pm UTC](https://discuss.elastic.co/t/error-handling-in-rest-api/15213/1 "2014-01-12T14:51:29Z")

</div>

Hi,  
I am trying out the elasticsearch javascript connection driver. It is  
working fine, but I am facing a problem with the error handling. To me it  
seems to be an elasticsearch rest api problem.

I am creating a request with the following body:  
{  
"facets": {},  
"query": {  
"simple\_query\_string": {  
"query": "test",  
"fields": ["\_all"],  
"analyzer": "snowball"  
}  
}  
}

This is working fine with elasticsearch 0.90.9+, however as expected, it  
does not work with 0.90.7. This is all logical since it is something that  
is introduced in 0.90.9. The problem is the error handling. In the response  
I get the following message:

{  
"error": "SearchPhaseExecutionException[Failed to execute phase [query],  
all shards failed; shardFailures {[8ClRn1lKRdeaawyrWGTUtw][myimages][0]:  
SearchParseException[[myimages][0]: from[-1],size[-1]: Parse Failure  
[Failed to parse source  
[{"facets":{},"query":{"simple\_query\_string":{"query":"test","fields":["\_all"],"analyzer":"snowball"}}}]]];  
nested: QueryParsingException[[myimages] No query registered for  
[simple\_query\_string]]; }{[8ClRn1lKRdeaawyrWGTUtw][mymusic][0]:  
SearchParseException[[mymusic][0]: from[-1],size[-1]: Parse Failure [Failed  
to parse source  
[{"facets":{},"query":{"simple\_query\_string":{"query":"test","fields":["\_all"],"analyzer":"snowball"}}}]]];  
nested: QueryParsingException[[mymusic] No query registered for  
[simple\_query\_string]]; }{[8ClRn1lKRdeaawyrWGTUtw][kibana-int][0]:  
SearchParseException[[kibana-int][0]: from[-1],size[-1]: Parse Failure  
[Failed to parse source  
[{"facets":{},"query":{"simple\_query\_string":{"query":"test","fields":["\_all"],"analyzer":"snowball"}}}]]];  
nested: QueryParsingException[[kibana-int] No query registered for  
[simple\_query\_string]]; }]",  
"status": 400  
}

The response using the javascript driver (in the browser) is a  
ConnectionFailure. I would like to obtain the message  
"QueryParsingException[[kibana-int] No query registered for  
[simple\_query\_string]]" out of this, that would really help. This is doable  
using the elasticsearch logs but I cannot present this message using  
javascript to the client.

Reproduction of this error is easy with my plugin at  
[http://www.gridshore.nl/esgui](http://www.gridshore.nl/esgui) with a local elasticsearch running on 0.90.7

Anybody has an idea how to improve this?

thanks

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/43180d10-d272-4750-ad4d-68dee4f55306%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/43180d10-d272-4750-ad4d-68dee4f55306%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<div class="post-metadata">

**Author:** ![Jettro\_Coenradie](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/jettro_coenradie/32/59704_2.png) [@Jettro\_Coenradie](https://discuss.elastic.co/u/Jettro_Coenradie)\
**Post date:** [January 12, 2014, 2:56pm UTC](https://discuss.elastic.co/t/error-handling-in-rest-api/15213/2 "2014-01-12T14:56:05Z")

</div>

Forgot to mention to reproduce in the plugin, go to the search tab, enter a  
term to search on and press the search button. You won't see a problem in  
the screen, but you will see errors in the console. The messages I have  
shown were obtained using charles (a proxy).

Op zondag 12 januari 2014 15:51:29 UTC+1 schreef Jettro Coenradie:

> Hi,  
> I am trying out the elasticsearch javascript connection driver. It is  
> working fine, but I am facing a problem with the error handling. To me it  
> seems to be an elasticsearch rest api problem.
> 
> I am creating a request with the following body:  
> {  
> "facets": {},  
> "query": {  
> "simple\_query\_string": {  
> "query": "test",  
> "fields": ["\_all"],  
> "analyzer": "snowball"  
> }  
> }  
> }
> 
> This is working fine with elasticsearch 0.90.9+, however as expected, it  
> does not work with 0.90.7. This is all logical since it is something that  
> is introduced in 0.90.9. The problem is the error handling. In the response  
> I get the following message:
> 
> {  
> "error": "SearchPhaseExecutionException[Failed to execute phase [query],  
> all shards failed; shardFailures {[8ClRn1lKRdeaawyrWGTUtw][myimages][0]:  
> SearchParseException[[myimages][0]: from[-1],size[-1]: Parse Failure  
> [Failed to parse source  
> [{"facets":{},"query":{"simple\_query\_string":{"query":"test","fields":["\_all"],"analyzer":"snowball"}}}]]];  
> nested: QueryParsingException[[myimages] No query registered for  
> [simple\_query\_string]]; }{[8ClRn1lKRdeaawyrWGTUtw][mymusic][0]:  
> SearchParseException[[mymusic][0]: from[-1],size[-1]: Parse Failure [Failed  
> to parse source  
> [{"facets":{},"query":{"simple\_query\_string":{"query":"test","fields":["\_all"],"analyzer":"snowball"}}}]]];  
> nested: QueryParsingException[[mymusic] No query registered for  
> [simple\_query\_string]]; }{[8ClRn1lKRdeaawyrWGTUtw][kibana-int][0]:  
> SearchParseException[[kibana-int][0]: from[-1],size[-1]: Parse Failure  
> [Failed to parse source  
> [{"facets":{},"query":{"simple\_query\_string":{"query":"test","fields":["\_all"],"analyzer":"snowball"}}}]]];  
> nested: QueryParsingException[[kibana-int] No query registered for  
> [simple\_query\_string]]; }]",  
> "status": 400  
> }
> 
> The response using the javascript driver (in the browser) is a  
> ConnectionFailure. I would like to obtain the message  
> "QueryParsingException[[kibana-int] No query registered for  
> [simple\_query\_string]]" out of this, that would really help. This is doable  
> using the elasticsearch logs but I cannot present this message using  
> javascript to the client.
> 
> Reproduction of this error is easy with my plugin at  
> [Elasticsearch gui](http://www.gridshore.nl/esgui) with a local elasticsearch running on 0.90.7
> 
> Anybody has an idea how to improve this?
> 
> thanks

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/e74eb8aa-839e-46d0-8d38-ce2a5182a863%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/e74eb8aa-839e-46d0-8d38-ce2a5182a863%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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:** [January 12, 2014, 4:06pm UTC](https://discuss.elastic.co/t/error-handling-in-rest-api/15213/3 "2014-01-12T16:06:07Z")

</div>

The reason why you receive a SearchPhaseExecutionException and many  
SearchParseExceptions is that your query is parsed at each shard and causes  
an error at that deeper level. ES wraps up the shards responses into a  
SearchPhaseExecutionException  
which is passed back to the client.

In most cases, all shards respond with same errors, but that is not always  
the case.

This certainly can be improved regarding the JSON formatting by a patch to  
ES so the REST action tries to parse error response from shards.

Another possibility would be processing the shards exceptions and just  
returning a short SearchPhaseExecutionException message saying something  
like "no query registered for ..." if all shard errors match.

In general, I would simply rely on the REST response codes (here: 400)  
which signals "bad request" and ignore the ES error messages since they are  
fluctuating.

Jörg

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAKdsXoEgmRHYXe6-9XaDrHjDPeb2Xq7%3D8bumetxAFcXbFHiB3Q%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAKdsXoEgmRHYXe6-9XaDrHjDPeb2Xq7%3D8bumetxAFcXbFHiB3Q%40mail.gmail.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 1:57am UTC](https://discuss.elastic.co/t/error-handling-in-rest-api/15213/4 "2017-07-06T01:57:13Z")

</div>


