OpenSearch/docs/reference/query-dsl/queries/regexp-query.asciidoc
Matthew L Daniel 53f2301eea Docs: Add clarifying text about regexp and terms
For the casual reader, the reference to "term queries" may be glossed over, yielding an unexpected result when using `regexp` queries.
This attempts to make that distinction more prominent.

Closes #6698
2014-07-03 11:39:57 +02:00

60 lines
1.7 KiB
Plaintext

[[query-dsl-regexp-query]]
=== Regexp Query
The `regexp` query allows you to use regular expression term queries.
See <<regexp-syntax>> for details of the supported regular expression language.
The "term queries" in that first sentence means that Elasticsearch will apply
the regexp to the terms produced by the tokenizer for that field, and not
to the original text of the field.
*Note*: The performance of a `regexp` query heavily depends on the
regular expression chosen. Matching everything like `.*` is very slow as
well as using lookaround regular expressions. If possible, you should
try to use a long prefix before your regular expression starts. Wildcard
matchers like `.*?+` will mostly lower performance.
[source,js]
--------------------------------------------------
{
"regexp":{
"name.first": "s.*y"
}
}
--------------------------------------------------
Boosting is also supported
[source,js]
--------------------------------------------------
{
"regexp":{
"name.first":{
"value":"s.*y",
"boost":1.2
}
}
}
--------------------------------------------------
You can also use special flags
[source,js]
--------------------------------------------------
{
"regexp":{
"name.first": {
"value": "s.*y",
"flags" : "INTERSECTION|COMPLEMENT|EMPTY"
}
}
}
--------------------------------------------------
Possible flags are `ALL`, `ANYSTRING`, `AUTOMATON`, `COMPLEMENT`,
`EMPTY`, `INTERSECTION`, `INTERVAL`, or `NONE`. Please check the
http://lucene.apache.org/core/4_9_0/core/org/apache/lucene/util/automaton/RegExp.html[Lucene
documentation] for their meaning
include::regexp-syntax.asciidoc[]