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


(Mark Waddle) #1

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


(Lukáš Vlček) #2

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 wrote:

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


(Mark Waddle) #3

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


(system) #4