# Best practices for executing user queries and reporting errors back to user

**URL:** <https://discuss.elastic.co/t/best-practices-for-executing-user-queries-and-reporting-errors-back-to-user/6461>\
**Category:** Elasticsearch\
**Created:** [January 22, 2012, 5:28pm UTC](https://discuss.elastic.co/t/best-practices-for-executing-user-queries-and-reporting-errors-back-to-user/6461 "2012-01-22T17:28:21Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Mark\_Waddle](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_waddle/32/2608_2.png) [@Mark\_Waddle](https://discuss.elastic.co/u/Mark_Waddle)\
**Post date:** [January 22, 2012, 5:28pm UTC](https://discuss.elastic.co/t/best-practices-for-executing-user-queries-and-reporting-errors-back-to-user/6461/1 "2012-01-22T17:28:21Z")

</div>

Hello,

I have an application that accepts complex queries from users and passes  
them straight to elastic search as query strings. Sometimes users write  
queries that cannot be parsed, and every shard reports an error. I am  
trying to distill these error messages down to the essence, such as,  
"cannot parse #$:@#$@#$", so that I can display an error message to the  
user, but I am finding that to be a difficult task. Does anyone have  
suggestions on how to parse the errors to present a user-readable error  
message?

Or am I going about this all the wrong way? Should I be filtering my  
queries before sending them to ES? Should I be using a different query  
parser? Something else?

Any help is appreciated. Thanks!

Mark

---

<div class="post-metadata">

**Author:** ![Lukas\_Vlcek1](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lukas_vlcek1/32/819_2.png) [@Lukas\_Vlcek1](https://discuss.elastic.co/u/Lukas_Vlcek1)\
**Post date:** [January 22, 2012, 8:07pm UTC](https://discuss.elastic.co/t/best-practices-for-executing-user-queries-and-reporting-errors-back-to-user/6461/2 "2012-01-22T20:07:10Z")

</div>

Hi,

that sounds like a difficult situation to me. You are not responsible for  
query creation but you want to validate it and if there are any errors you  
want to report them back in "human readable form". In other words you are  
in the middle of the chain and you control neither input query string nor  
the parsing process (which happens in elasticsearch and error messages can  
be subject to change with new release).

However, you can try to check if the input is valid JSON prior hitting ES  
(for example using Jackson library). If it is a valid JSON and you can get  
any general query then you can not do a lot more (there is no formal  
grammar for ES queries). May be you can also consider rebuilding the query  
from given JSON into new query using ES Java API. This could minimize  
chance of input user query errors. But generally parsing ES errors is IMO  
too complex.

Regards,  
Lukas

On Sun, Jan 22, 2012 at 6:28 PM, Mark Waddle [mark@markwaddle.com](mailto:mark@markwaddle.com) wrote:

> Hello,
> 
> I have an application that accepts complex queries from users and passes  
> them straight to Elasticsearch as query strings. Sometimes users write  
> queries that cannot be parsed, and every shard reports an error. I am  
> trying to distill these error messages down to the essence, such as,  
> "cannot parse #$:@#$@#$", so that I can display an error message to the  
> user, but I am finding that to be a difficult task. Does anyone have  
> suggestions on how to parse the errors to present a user-readable error  
> message?
> 
> Or am I going about this all the wrong way? Should I be filtering my  
> queries before sending them to ES? Should I be using a different query  
> parser? Something else?
> 
> Any help is appreciated. Thanks!
> 
> Mark

---

<div class="post-metadata">

**Author:** ![Mark\_Waddle](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/mark_waddle/32/2608_2.png) [@Mark\_Waddle](https://discuss.elastic.co/u/Mark_Waddle)\
**Post date:** [January 22, 2012, 8:55pm UTC](https://discuss.elastic.co/t/best-practices-for-executing-user-queries-and-reporting-errors-back-to-user/6461/3 "2012-01-22T20:55:14Z")

</div>

Thanks Lukas.

To clarify, the user is providing a Lucene format query string, not a JSON  
format.

I have used the javascript Lucene query validator in the past, but it has  
some bugs. I was hoping someone else had a more robust solution. Or had a  
recommendation for a better way to support complex queries from power users.

Thanks,  
Mark

---

<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:41am UTC](https://discuss.elastic.co/t/best-practices-for-executing-user-queries-and-reporting-errors-back-to-user/6461/4 "2017-07-06T03:41:52Z")

</div>


