regexp-query.asciidoc 2.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859606162636465666768697071727374757677787980818283848586878889
  1. [[query-dsl-regexp-query]]
  2. === Regexp query
  3. ++++
  4. <titleabbrev>Regexp</titleabbrev>
  5. ++++
  6. Returns documents that contain terms matching a
  7. https://en.wikipedia.org/wiki/Regular_expression[regular expression].
  8. A regular expression is a way to match patterns in data using placeholder
  9. characters, called operators. For a list of operators supported by the
  10. `regexp` query, see <<regexp-syntax, Regular expression syntax>>.
  11. [[regexp-query-ex-request]]
  12. ==== Example request
  13. The following search returns documents where the `user` field contains any term
  14. that begins with `k` and ends with `y`. The `.*` operators match any
  15. characters of any length, including no characters. Matching
  16. terms can include `ky`, `kay`, and `kimchy`.
  17. [source,js]
  18. ----
  19. GET /_search
  20. {
  21. "query": {
  22. "regexp": {
  23. "user": {
  24. "value": "k.*y",
  25. "flags" : "ALL",
  26. "max_determinized_states": 10000,
  27. "rewrite": "constant_score"
  28. }
  29. }
  30. }
  31. }
  32. ----
  33. // CONSOLE
  34. [[regexp-top-level-params]]
  35. ==== Top-level parameters for `regexp`
  36. `<field>`::
  37. (Required, object) Field you wish to search.
  38. [[regexp-query-field-params]]
  39. ==== Parameters for `<field>`
  40. `value`::
  41. (Required, string) Regular expression for terms you wish to find in the provided
  42. `<field>`. For a list of supported operators, see <<regexp-syntax, Regular
  43. expression syntax>>.
  44. +
  45. --
  46. By default, regular expressions are limited to 1,000 characters. You can change
  47. this limit using the <<index-max-regex-length, `index.max_regex_length`>>
  48. setting.
  49. [WARNING]
  50. =====
  51. The performance of the `regexp` query can vary based on the regular expression
  52. provided. To improve performance, avoid using wildcard patterns, such as `.*` or
  53. `.*?+`, without a prefix or suffix.
  54. =====
  55. --
  56. `flags`::
  57. (Optional, string) Enables optional operators for the regular expression. For
  58. valid values and more information, see <<regexp-optional-operators, Regular
  59. expression syntax>>.
  60. `max_determinized_states`::
  61. +
  62. --
  63. (Optional, integer) Maximum number of
  64. https://en.wikipedia.org/wiki/Deterministic_finite_automaton[automaton states]
  65. required for the query. Default is `10000`.
  66. {es} uses https://lucene.apache.org/core/[Apache Lucene] internally to parse
  67. regular expressions. Lucene converts each regular expression to a finite
  68. automaton containing a number of determinized states.
  69. You can use this parameter to prevent that conversion from unintentionally
  70. consuming too many resources. You may need to increase this limit to run complex
  71. regular expressions.
  72. --
  73. `rewrite`::
  74. (Optional, string) Method used to rewrite the query. For valid values and more
  75. information, see the <<query-dsl-multi-term-rewrite, `rewrite` parameter>>.