[[query-dsl-regexp-query]] === Regexp query ++++ Regexp ++++ Returns documents that contain terms matching a https://en.wikipedia.org/wiki/Regular_expression[regular expression]. 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-query-ex-request]] ==== Example request 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`. [source,js] ---- GET /_search { "query": { "regexp": { "user": { "value": "k.*y", "flags" : "ALL", "max_determinized_states": 10000, "rewrite": "constant_score" } } } } ---- // CONSOLE [[regexp-top-level-params]] ==== Top-level parameters for `regexp` ``:: (Required, object) Field you wish to search. [[regexp-query-field-params]] ==== Parameters for `` `value`:: (Required, string) Regular expression for terms you wish to find in the provided ``. For a list of supported operators, see <>. + -- By default, regular expressions are limited to 1,000 characters. You can change this limit using the <> setting. [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. ===== -- `flags`:: (Optional, string) Enables optional operators for the regular expression. For valid values and more information, see <>. `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. 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. -- `rewrite`:: (Optional, string) Method used to rewrite the query. For valid values and more information, see the <>.