Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What is escape property in query_string in elasticsearch

I have a problem using wildcard in query_string in elasticsearch.I can not find documentation for the "escape" property in query_string when the value is "true" I got some results but when it is "false" the result is zero.

{
                    "query_string": {
                        "query": "*Serial\\+*",
                        "fields": [
                            "info.name^1.0"
                        ],
                        "type": "best_fields",
                        "allow_leading_wildcard": true,
                        "analyze_wildcard": true,
                        "escape": true,
                        "auto_generate_synonyms_phrase_query": true,
                        "fuzzy_transpositions": true,
                        "boost": 1.0
                    }
                }

can anybody explain the "escape" property?

like image 567
saba safavi Avatar asked Oct 20 '25 19:10

saba safavi


1 Answers

Weird that its not documented, but looking at the source code we can see:

Es query string source code

If "escape" is "true", the code calls org.apache.lucene.queryparser.classic.QueryParser.escape

On the query string, the function itself is documented as

Returns a String where those characters that QueryParser expects to be escaped are escaped by a preceding \.

So looks like this flag is just used to automatically escape characters for you, so you don't have to manually escape them

like image 190
Ron Serruya Avatar answered Oct 23 '25 11:10

Ron Serruya