[DOCS] Note double backslashes (`\\`) are required to escape JSON chars (#46863)

This commit is contained in:
Andrew Naguib 2019-09-30 17:10:18 +02:00 committed by James Rodewig
parent 24b3703005
commit ae85a0e29a
1 changed files with 18 additions and 3 deletions

View File

@ -271,12 +271,27 @@ of a sub-query:
If you need to use any of the characters which function as operators in your
query itself (and not as operators), then you should escape them with
a leading backslash. For instance, to search for `(1+1)=2`, you would
need to write your query as `\(1\+1\)\=2`.
need to write your query as `\(1\+1\)\=2`. When using JSON for the request body, two preceding backslashes (`\\`) are required; the backslash is a reserved escaping character in JSON strings.
[source,console]
----
GET /twitter/_search
Content-Type: application/json
{
"query" : {
"query_string" : {
"query" : "kimchy\\!",
"fields" : ["user"]
}
}
}
----
// TEST[setup:twitter]
The reserved characters are: `+ - = && || > < ! ( ) { } [ ] ^ " ~ * ? : \ /`
Failing to escape these special characters correctly could lead to a syntax
error which prevents your query from running.
Failing to escape these special characters correctly could lead to a syntax error which prevents your query from running.
NOTE: `<` and `>` can't be escaped at all. The only way to prevent them from
attempting to create a range query is to remove them from the query string