1
0

regexp-query.asciidoc 2.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576777879808182838485868788899091929394
  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.id` 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,console]
  18. ----
  19. GET /_search
  20. {
  21. "query": {
  22. "regexp": {
  23. "user.id": {
  24. "value": "k.*y",
  25. "flags": "ALL",
  26. "max_determinized_states": 10000,
  27. "rewrite": "constant_score"
  28. }
  29. }
  30. }
  31. }
  32. ----
  33. [[regexp-top-level-params]]
  34. ==== Top-level parameters for `regexp`
  35. `<field>`::
  36. (Required, object) Field you wish to search.
  37. [[regexp-query-field-params]]
  38. ==== Parameters for `<field>`
  39. `value`::
  40. (Required, string) Regular expression for terms you wish to find in the provided
  41. `<field>`. For a list of supported operators, see <<regexp-syntax, Regular
  42. expression syntax>>.
  43. +
  44. --
  45. By default, regular expressions are limited to 1,000 characters. You can change
  46. this limit using the <<index-max-regex-length, `index.max_regex_length`>>
  47. setting.
  48. [WARNING]
  49. =====
  50. The performance of the `regexp` query can vary based on the regular expression
  51. provided. To improve performance, avoid using wildcard patterns, such as `.*` or
  52. `.*?+`, without a prefix or suffix.
  53. =====
  54. --
  55. `flags`::
  56. (Optional, string) Enables optional operators for the regular expression. For
  57. valid values and more information, see <<regexp-optional-operators, Regular
  58. expression syntax>>.
  59. `max_determinized_states`::
  60. +
  61. --
  62. (Optional, integer) Maximum number of
  63. https://en.wikipedia.org/wiki/Deterministic_finite_automaton[automaton states]
  64. required for the query. Default is `10000`.
  65. {es} uses https://lucene.apache.org/core/[Apache Lucene] internally to parse
  66. regular expressions. Lucene converts each regular expression to a finite
  67. automaton containing a number of determinized states.
  68. You can use this parameter to prevent that conversion from unintentionally
  69. consuming too many resources. You may need to increase this limit to run complex
  70. regular expressions.
  71. --
  72. `rewrite`::
  73. (Optional, string) Method used to rewrite the query. For valid values and more
  74. information, see the <<query-dsl-multi-term-rewrite, `rewrite` parameter>>.
  75. [[regexp-query-notes]]
  76. ==== Notes
  77. ===== Allow expensive queries
  78. Regexp queries will not be executed if <<query-dsl-allow-expensive-queries, `search.allow_expensive_queries`>>
  79. is set to false.