Elasticsearch Java API: query string validation -


i'm using elasticsearch java api (version 2.1.1) query string query. query string entered user , may contain syntax errors. right seems query sent server, response shardfailure , exception thrown.

is there easy way validate query in api before sending server? right i'm catching exception, not feel right bother server these queries.

query built this:

querybuilders.querystringquery("error)"); 

example response:

queryparsingexception[failed parse query [error)]]; nested: notserializableexceptionwrapper[cannot parse 'error)': encountered " ")" ") "" @ line 1, column 5.

edit: clear: totally ok query contain special characters brackets or quotes. want check if user entered correct search query (e.g. brackets/quotes in pairs).

you have parse string , escape special characters before passing string method.

querybuilders.querystringquery(escapespecialcharacters("error)"));  string escapespecialcharacters(string str) {     str.replaceall(/[^\sa-za-z0-9]/, "\\'"); } 

you can remove special characters if want.

hope helps.


Comments

Popular posts from this blog

javascript - jQuery: Add class depending on URL in the best way -

caching - How to check if a url path exists in the service worker cache -

Redirect to a HTTPS version using .htaccess -