fuzzy-query.asciidoc 1.8 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778
  1. [[query-dsl-fuzzy-query]]
  2. === Fuzzy query
  3. ++++
  4. <titleabbrev>Fuzzy</titleabbrev>
  5. ++++
  6. The fuzzy query uses similarity based on Levenshtein edit distance.
  7. ==== String fields
  8. The `fuzzy` query generates matching terms that are within the
  9. maximum edit distance specified in `fuzziness` and then checks the term
  10. dictionary to find out which of those generated terms actually exist in the
  11. index. The final query uses up to `max_expansions` matching terms.
  12. Here is a simple example:
  13. [source,js]
  14. --------------------------------------------------
  15. GET /_search
  16. {
  17. "query": {
  18. "fuzzy" : { "user" : "ki" }
  19. }
  20. }
  21. --------------------------------------------------
  22. // CONSOLE
  23. Or with more advanced settings:
  24. [source,js]
  25. --------------------------------------------------
  26. GET /_search
  27. {
  28. "query": {
  29. "fuzzy" : {
  30. "user" : {
  31. "value": "ki",
  32. "boost": 1.0,
  33. "fuzziness": 2,
  34. "prefix_length": 0,
  35. "max_expansions": 100
  36. }
  37. }
  38. }
  39. }
  40. --------------------------------------------------
  41. // CONSOLE
  42. [float]
  43. ===== Parameters
  44. [horizontal]
  45. `fuzziness`::
  46. The maximum edit distance. Defaults to `AUTO`. See <<fuzziness>>.
  47. `prefix_length`::
  48. The number of initial characters which will not be ``fuzzified''. This
  49. helps to reduce the number of terms which must be examined. Defaults
  50. to `0`.
  51. `max_expansions`::
  52. The maximum number of terms that the `fuzzy` query will expand to.
  53. Defaults to `50`.
  54. `transpositions`::
  55. Whether fuzzy transpositions (`ab` -> `ba`) are supported.
  56. Default is `true`.
  57. WARNING: This query can be very heavy if `prefix_length` is set to `0` and if
  58. `max_expansions` is set to a high number. It could result in every term in the
  59. index being examined!