What is the Java API to escape Elasticsearch special characters?

6.3k views Asked by At

I'm trying to perform the following query with the Java API:

"query": {
  "bool" : {
    "must" : [ {
      "field" : {
        "space-time-id.timestamp" : "2014-03-17T16:57:47.136-07:00"
      }
    } ]
  }
}

This fails presumably because the value has colons (which are special characters). Can someone point me to the Java API that escapes such characters?

2

There are 2 answers

0
Noel Yap On BEST ANSWER

org.apache.lucene.queryparser.classic.QueryParser.escape()

0
Pär Eriksson On

You can also use org.apache.lucene.queryparser.flexible.standard.QueryParserUtil.escape()

;)

Looks like the implementation is the same..