fuzzy-query.asciidoc 1.7 KB

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