regexp-query.asciidoc 1.7 KB

1234567891011121314151617181920212223242526272829303132333435363738394041424344454647484950515253545556575859
  1. [[query-dsl-regexp-query]]
  2. === Regexp Query
  3. The `regexp` query allows you to use regular expression term queries.
  4. See <<regexp-syntax>> for details of the supported regular expression language.
  5. The "term queries" in that first sentence means that Elasticsearch will apply
  6. the regexp to the terms produced by the tokenizer for that field, and not
  7. to the original text of the field.
  8. *Note*: The performance of a `regexp` query heavily depends on the
  9. regular expression chosen. Matching everything like `.*` is very slow as
  10. well as using lookaround regular expressions. If possible, you should
  11. try to use a long prefix before your regular expression starts. Wildcard
  12. matchers like `.*?+` will mostly lower performance.
  13. [source,js]
  14. --------------------------------------------------
  15. {
  16. "regexp":{
  17. "name.first": "s.*y"
  18. }
  19. }
  20. --------------------------------------------------
  21. Boosting is also supported
  22. [source,js]
  23. --------------------------------------------------
  24. {
  25. "regexp":{
  26. "name.first":{
  27. "value":"s.*y",
  28. "boost":1.2
  29. }
  30. }
  31. }
  32. --------------------------------------------------
  33. You can also use special flags
  34. [source,js]
  35. --------------------------------------------------
  36. {
  37. "regexp":{
  38. "name.first": {
  39. "value": "s.*y",
  40. "flags" : "INTERSECTION|COMPLEMENT|EMPTY"
  41. }
  42. }
  43. }
  44. --------------------------------------------------
  45. Possible flags are `ALL`, `ANYSTRING`, `AUTOMATON`, `COMPLEMENT`,
  46. `EMPTY`, `INTERSECTION`, `INTERVAL`, or `NONE`. Please check the
  47. http://lucene.apache.org/core/4_9_0/core/org/apache/lucene/util/automaton/RegExp.html[Lucene
  48. documentation] for their meaning
  49. include::regexp-syntax.asciidoc[]