fuzzy-query.asciidoc 2.7 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105
  1. [[query-dsl-fuzzy-query]]
  2. === Fuzzy query
  3. ++++
  4. <titleabbrev>Fuzzy</titleabbrev>
  5. ++++
  6. Returns documents that contain terms similar to the search term, as measured by
  7. a https://en.wikipedia.org/wiki/Levenshtein_distance[Levenshtein edit distance].
  8. An edit distance is the number of one-character changes needed to turn one term
  9. into another. These changes can include:
  10. * Changing a character (**b**ox → **f**ox)
  11. * Removing a character (**b**lack → lack)
  12. * Inserting a character (sic → sic**k**)
  13. * Transposing two adjacent characters (**ac**t → **ca**t)
  14. To find similar terms, the `fuzzy` query creates a set of all possible
  15. variations, or expansions, of the search term within a specified edit distance.
  16. The query then returns exact matches for each expansion.
  17. [[fuzzy-query-ex-request]]
  18. ==== Example requests
  19. [[fuzzy-query-ex-simple]]
  20. ===== Simple example
  21. [source,console]
  22. ----
  23. GET /_search
  24. {
  25. "query": {
  26. "fuzzy": {
  27. "user.id": {
  28. "value": "ki"
  29. }
  30. }
  31. }
  32. }
  33. ----
  34. [[fuzzy-query-ex-advanced]]
  35. ===== Example using advanced parameters
  36. [source,console]
  37. ----
  38. GET /_search
  39. {
  40. "query": {
  41. "fuzzy": {
  42. "user.id": {
  43. "value": "ki",
  44. "fuzziness": "AUTO",
  45. "max_expansions": 50,
  46. "prefix_length": 0,
  47. "transpositions": true,
  48. "rewrite": "constant_score"
  49. }
  50. }
  51. }
  52. }
  53. ----
  54. [[fuzzy-query-top-level-params]]
  55. ==== Top-level parameters for `fuzzy`
  56. `<field>`::
  57. (Required, object) Field you wish to search.
  58. [[fuzzy-query-field-params]]
  59. ==== Parameters for `<field>`
  60. `value`::
  61. (Required, string) Term you wish to find in the provided `<field>`.
  62. `fuzziness`::
  63. (Optional, string) Maximum edit distance allowed for matching. See <<fuzziness>>
  64. for valid values and more information.
  65. `max_expansions`::
  66. +
  67. --
  68. (Optional, integer) Maximum number of variations created. Defaults to `50`.
  69. WARNING: Avoid using a high value in the `max_expansions` parameter, especially
  70. if the `prefix_length` parameter value is `0`. High values in the
  71. `max_expansions` parameter can cause poor performance due to the high number of
  72. variations examined.
  73. --
  74. `prefix_length`::
  75. (Optional, integer) Number of beginning characters left unchanged when creating
  76. expansions. Defaults to `0`.
  77. `transpositions`::
  78. (Optional, boolean) Indicates whether edits include transpositions of two
  79. adjacent characters (ab → ba). Defaults to `true`.
  80. `rewrite`::
  81. (Optional, string) Method used to rewrite the query. For valid values and more
  82. information, see the <<query-dsl-multi-term-rewrite, `rewrite` parameter>>.
  83. [[fuzzy-query-notes]]
  84. ==== Notes
  85. Fuzzy queries will not be executed if <<query-dsl-allow-expensive-queries, `search.allow_expensive_queries`>>
  86. is set to false.