Escaping characters in a JSON query?

Hi all, I've been having difficulty creating a JSON query to find
fields that have multiple colons ':' in the query string. Multiple
colons results in a query parse failure, the console log shows
Caused by: org.apache.lucene.queryParser.ParseException: Cannot parse
'ends:with:colon': Encountered " ":" ": "" at line 1, column 9.

Although I can run wildcard queries or fuzzy queries, I'd like to be
able to do an exact match on the query string. Does anyone know how
to escape the characters in a query, or else have suggestions about
how to work around this?

Full gist recreation: https://gist.github.com/1070840

Thanks!
scott

Hi Scott

On Thu, 2011-07-07 at 17:23 -0700, drv_ wrote:

Hi all, I've been having difficulty creating a JSON query to find
fields that have multiple colons ':' in the query string. Multiple
colons results in a query parse failure, the console log shows
Caused by: org.apache.lucene.queryParser.ParseException: Cannot parse
'ends:with:colon': Encountered " ":" ": "" at line 1, column 9.

Although I can run wildcard queries or fuzzy queries, I'd like to be
able to do an exact match on the query string. Does anyone know how
to escape the characters in a query, or else have suggestions about
how to work around this?

Yes, the lucene query string syntax, while useful for power users,
really needs to be parsed and corrected before being sent to ES.

You have three options here:

  1. I have written a Perl module Elasticsearch::QueryParser
    which will correct errors in query strings, and allow you
    to filter out particular elements (eg field: prefix) from
    your query string

http://beta.metacpan.org/module/ElasticSearch::QueryParser

  1. You can write your own parser in the language of your choice

  2. Simplest option: use the 'text' family of queries, which don't
    have the advanced features of the lucene query syntax (eg:

    AND OR NOT () {} + -

    but instead just analyze the text and do a full text search,
    without throwing any errors

clint