fuzzy-query.asciidoc 2.6 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102
  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 http://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,js]
  22. ----
  23. GET /_search
  24. {
  25. "query": {
  26. "fuzzy": {
  27. "user": {
  28. "value": "ki"
  29. }
  30. }
  31. }
  32. }
  33. ----
  34. // CONSOLE
  35. [[fuzzy-query-ex-advanced]]
  36. ===== Example using advanced parameters
  37. [source,js]
  38. ----
  39. GET /_search
  40. {
  41. "query": {
  42. "fuzzy": {
  43. "user": {
  44. "value": "ki",
  45. "fuzziness": "AUTO",
  46. "max_expansions": 50,
  47. "prefix_length": 0,
  48. "transpositions": true,
  49. "rewrite": "constant_score"
  50. }
  51. }
  52. }
  53. }
  54. ----
  55. // CONSOLE
  56. [[fuzzy-query-top-level-params]]
  57. ==== Top-level parameters for `fuzzy`
  58. `<field>`::
  59. (Required, object) Field you wish to search.
  60. [[fuzzy-query-field-params]]
  61. ==== Parameters for `<field>`
  62. `value`::
  63. (Required, string) Term you wish to find in the provided `<field>`.
  64. `fuzziness`::
  65. (Optional, string) Maximum edit distance allowed for matching. See <<fuzziness>>
  66. for valid values and more information.
  67. `max_expansions`::
  68. +
  69. --
  70. (Optional, integer) Maximum number of variations created. Defaults to `50`.
  71. WARNING: Avoid using a high value in the `max_expansions` parameter, especially
  72. if the `prefix_length` parameter value is `0`. High values in the
  73. `max_expansions` parameter can cause poor performance due to the high number of
  74. variations examined.
  75. --
  76. `prefix_length`::
  77. (Optional, integer) Number of beginning characters left unchanged when creating
  78. expansions. Defaults to `0`.
  79. `transpositions`::
  80. (Optional, boolean) Indicates whether edits include transpositions of two
  81. adjacent characters (ab → ba). Defaults to `true`.
  82. `rewrite`::
  83. (Optional, string) Method used to rewrite the query. For valid values and more
  84. information, see the <<query-dsl-multi-term-rewrite, `rewrite` parameter>>.