[DOCS] Adds note about escaping backslashes in regex (#89276)

* [DOCS] Adds note about escaping backslashes in regex

* Fix typo

* Simplify example
This commit is contained in:
Abdon Pijpelink 2022-08-17 09:40:30 +02:00 committed by GitHub
parent 03f3c8119a
commit f2257cae89
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23

View file

@ -38,6 +38,37 @@ backslash or surround it with double quotes. For example:
"john@smith.com" # renders as 'john@smith.com'
....
[NOTE]
====
The backslash is an escape character in both JSON strings and regular
expressions. You need to escape both backslashes in a query, unless you use a
language client, which takes care of this. For example, the string `a\b` needs
to be indexed as `"a\\b"`:
[source,console]
--------------------------------------------------
PUT my-index-000001/_doc/1
{
"my_field": "a\\b"
}
--------------------------------------------------
This document matches the following `regexp` query:
[source,console]
--------------------------------------------------
GET my-index-000001/_search
{
"query": {
"regexp": {
"my_field.keyword": "a\\\\.*"
}
}
}
--------------------------------------------------
//TEST[continued]
====
[discrete]
[[regexp-standard-operators]]