2013-08-28 19:24:34 -04:00
|
|
|
[[query-dsl-regexp-query]]
|
2019-07-18 10:18:11 -04:00
|
|
|
=== Regexp query
|
|
|
|
++++
|
|
|
|
<titleabbrev>Regexp</titleabbrev>
|
|
|
|
++++
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2019-07-24 08:37:37 -04:00
|
|
|
Returns documents that contain terms matching a
|
|
|
|
https://en.wikipedia.org/wiki/Regular_expression[regular expression].
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2019-07-24 08:37:37 -04:00
|
|
|
A regular expression is a way to match patterns in data using placeholder
|
|
|
|
characters, called operators. For a list of operators supported by the
|
|
|
|
`regexp` query, see <<regexp-syntax, Regular expression syntax>>.
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2019-07-24 08:37:37 -04:00
|
|
|
[[regexp-query-ex-request]]
|
|
|
|
==== Example request
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2019-07-24 08:37:37 -04:00
|
|
|
The following search returns documents where the `user` field contains any term
|
|
|
|
that begins with `k` and ends with `y`. The `.*` operators match any
|
|
|
|
characters of any length, including no characters. Matching
|
|
|
|
terms can include `ky`, `kay`, and `kimchy`.
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2019-09-09 12:35:50 -04:00
|
|
|
[source,console]
|
2019-07-24 08:37:37 -04:00
|
|
|
----
|
2016-05-24 05:58:43 -04:00
|
|
|
GET /_search
|
2013-08-28 19:24:34 -04:00
|
|
|
{
|
2016-05-24 05:58:43 -04:00
|
|
|
"query": {
|
2019-07-24 08:37:37 -04:00
|
|
|
"regexp": {
|
|
|
|
"user": {
|
|
|
|
"value": "k.*y",
|
|
|
|
"flags" : "ALL",
|
|
|
|
"max_determinized_states": 10000,
|
|
|
|
"rewrite": "constant_score"
|
2016-05-24 05:58:43 -04:00
|
|
|
}
|
2013-08-28 19:24:34 -04:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
2019-07-24 08:37:37 -04:00
|
|
|
----
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
|
2019-07-24 08:37:37 -04:00
|
|
|
[[regexp-top-level-params]]
|
|
|
|
==== Top-level parameters for `regexp`
|
|
|
|
`<field>`::
|
|
|
|
(Required, object) Field you wish to search.
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2019-07-24 08:37:37 -04:00
|
|
|
[[regexp-query-field-params]]
|
|
|
|
==== Parameters for `<field>`
|
|
|
|
`value`::
|
|
|
|
(Required, string) Regular expression for terms you wish to find in the provided
|
|
|
|
`<field>`. For a list of supported operators, see <<regexp-syntax, Regular
|
|
|
|
expression syntax>>.
|
|
|
|
+
|
|
|
|
--
|
|
|
|
By default, regular expressions are limited to 1,000 characters. You can change
|
|
|
|
this limit using the <<index-max-regex-length, `index.max_regex_length`>>
|
|
|
|
setting.
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2019-07-24 08:37:37 -04:00
|
|
|
[WARNING]
|
|
|
|
=====
|
|
|
|
The performance of the `regexp` query can vary based on the regular expression
|
|
|
|
provided. To improve performance, avoid using wildcard patterns, such as `.*` or
|
|
|
|
`.*?+`, without a prefix or suffix.
|
|
|
|
=====
|
|
|
|
--
|
2014-11-10 13:43:48 -05:00
|
|
|
|
2019-07-24 08:37:37 -04:00
|
|
|
`flags`::
|
|
|
|
(Optional, string) Enables optional operators for the regular expression. For
|
|
|
|
valid values and more information, see <<regexp-optional-operators, Regular
|
|
|
|
expression syntax>>.
|
|
|
|
|
|
|
|
`max_determinized_states`::
|
|
|
|
+
|
|
|
|
--
|
|
|
|
(Optional, integer) Maximum number of
|
|
|
|
https://en.wikipedia.org/wiki/Deterministic_finite_automaton[automaton states]
|
|
|
|
required for the query. Default is `10000`.
|
|
|
|
|
|
|
|
{es} uses https://lucene.apache.org/core/[Apache Lucene] internally to parse
|
|
|
|
regular expressions. Lucene converts each regular expression to a finite
|
|
|
|
automaton containing a number of determinized states.
|
2013-10-07 08:42:13 -04:00
|
|
|
|
2019-07-24 08:37:37 -04:00
|
|
|
You can use this parameter to prevent that conversion from unintentionally
|
|
|
|
consuming too many resources. You may need to increase this limit to run complex
|
|
|
|
regular expressions.
|
|
|
|
--
|
2018-02-23 13:41:24 -05:00
|
|
|
|
2019-07-24 08:37:37 -04:00
|
|
|
`rewrite`::
|
|
|
|
(Optional, string) Method used to rewrite the query. For valid values and more
|
|
|
|
information, see the <<query-dsl-multi-term-rewrite, `rewrite` parameter>>.
|