mike
mike

Reputation: 639

How to escape special words such "AND" , "OR" in elastic search query string

I'm trying to build a elasticsearch query string query. It is mentioned that reserved or special characters must to be escaped.

https://www.elastic.co/guide/en/elasticsearch/reference/2.1/query-dsl-query-string-query.html#_reserved_characters

The reserved characters are: + - = && || > < ! ( ) { } [ ] ^ " ~ * ? : \ /

Failing to escape these special characters correctly could lead to a syntax error which prevents your query from running."

My question is: How can I escape the "special words" such "AND" or "OR". For example I would like to get the documents matching the text "NOW OR NEVER" (on all/any field) and that have status "active" OR "pending". The query below doesn't seem to work(OR is not escaped by elasticsearch).

NOW \OR NEVER status:(active OR pending) 

Upvotes: 2

Views: 1252

Answers (1)

dk-na
dk-na

Reputation: 141

You can try wrapping your text in double-quotes:

GET your_index/_search?q=status:(active OR pending) AND "NOW OR NEVER"

Upvotes: 2

Related Questions