| 123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100 | [[query-dsl-regexp-query]]=== Regexp query++++<titleabbrev>Regexp</titleabbrev>++++Returns documents that contain terms matching a{wikipedia}/Regular_expression[regular expression].A regular expression is a way to match patterns in data using placeholdercharacters, called operators. For a list of operators supported by the`regexp` query, see <<regexp-syntax, Regular expression syntax>>.[[regexp-query-ex-request]]==== Example requestThe following search returns documents where the `user.id` field contains any termthat begins with `k` and ends with `y`. The `.*` operators match anycharacters of any length, including no characters. Matchingterms can include `ky`, `kay`, and `kimchy`.[source,console]----GET /_search{  "query": {    "regexp": {      "user.id": {        "value": "k.*y",        "flags": "ALL",        "case_insensitive": true,        "max_determinized_states": 10000,        "rewrite": "constant_score"      }    }  }}----[[regexp-top-level-params]]==== Top-level parameters for `regexp``<field>`::(Required, object) Field you wish to search.[[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, Regularexpression syntax>>.+--By default, regular expressions are limited to 1,000 characters. You can changethis limit using the <<index-max-regex-length, `index.max_regex_length`>>setting.[WARNING]=====The performance of the `regexp` query can vary based on the regular expressionprovided. 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. Forvalid values and more information, see <<regexp-optional-operators, Regularexpression syntax>>.`case_insensitive`::(Optional, boolean) allows case insensitive matching of the regular expressionvalue with the indexed field values when set to true. Default is false which meansthe case sensitivity of matching depends on the underlying field's mapping.`max_determinized_states`::+--(Optional, integer) Maximum number of{wikipedia}/Deterministic_finite_automaton[automaton states]required for the query. Default is `10000`.{es} uses https://lucene.apache.org/core/[Apache Lucene] internally to parseregular expressions. Lucene converts each regular expression to a finiteautomaton containing a number of determinized states.You can use this parameter to prevent that conversion from unintentionallyconsuming too many resources. You may need to increase this limit to run complexregular expressions.--`rewrite`::(Optional, string) Method used to rewrite the query. For valid values and moreinformation, see the <<query-dsl-multi-term-rewrite, `rewrite` parameter>>.[[regexp-query-notes]]==== Notes===== Allow expensive queriesRegexp queries will not be executed if <<query-dsl-allow-expensive-queries, `search.allow_expensive_queries`>>is set to false.
 |