fuzzy-query.asciidoc 1.8 KB

12345678910111213141516171819202122232425262728293031323334353637383940414243444546474849505152535455565758596061626364656667686970717273747576
  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 all possible 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.
  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. "transpositions": false
  34. }
  35. }
  36. }
  37. }
  38. --------------------------------------------------
  39. // CONSOLE
  40. [float]
  41. ===== Parameters
  42. [horizontal]
  43. `fuzziness`::
  44. The maximum edit distance. Defaults to `AUTO`. See <<fuzziness>>.
  45. `prefix_length`::
  46. The number of initial characters which will not be ``fuzzified''. This
  47. helps to reduce the number of terms which must be examined. Defaults
  48. to `0`.
  49. `max_expansions`::
  50. The maximum number of terms that the `fuzzy` query will expand to.
  51. Defaults to `50`.
  52. `transpositions`::
  53. Whether fuzzy transpositions (`ab` -> `ba`) are supported.
  54. Default is `true`.
  55. WARNING: This query can be very heavy if `prefix_length` is set to `0` and if
  56. `max_expansions` is set to a high number. It could result in every term in the
  57. index being examined!