浏览代码

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

Andrew Naguib 6 年之前
父节点
当前提交
b4506019d5
共有 1 个文件被更改,包括 18 次插入3 次删除
  1. 18 3
      docs/reference/query-dsl/query-string-syntax.asciidoc

+ 18 - 3
docs/reference/query-dsl/query-string-syntax.asciidoc

@@ -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