fuzzy-query.asciidoc 2.4 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101
  1. [[query-dsl-fuzzy-query]]
  2. === Fuzzy Query
  3. The fuzzy query uses similarity based on Levenshtein edit distance for
  4. `string` fields, and a `+/-` margin on numeric and date fields.
  5. ==== String fields
  6. The `fuzzy` query generates all possible matching terms that are within the
  7. maximum edit distance specified in `fuzziness` and then checks the term
  8. dictionary to find out which of those generated terms actually exist in the
  9. index.
  10. Here is a simple example:
  11. [source,js]
  12. --------------------------------------------------
  13. {
  14. "fuzzy" : { "user" : "ki" }
  15. }
  16. --------------------------------------------------
  17. Or with more advanced settings:
  18. [source,js]
  19. --------------------------------------------------
  20. {
  21. "fuzzy" : {
  22. "user" : {
  23. "value" : "ki",
  24. "boost" : 1.0,
  25. "fuzziness" : 2,
  26. "prefix_length" : 0,
  27. "max_expansions": 100
  28. }
  29. }
  30. }
  31. --------------------------------------------------
  32. [float]
  33. ===== Parameters
  34. [horizontal]
  35. `fuzziness`::
  36. The maximum edit distance. Defaults to `AUTO`. See <<fuzziness>>.
  37. `prefix_length`::
  38. The number of initial characters which will not be ``fuzzified''. This
  39. helps to reduce the number of terms which must be examined. Defaults
  40. to `0`.
  41. `max_expansions`::
  42. The maximum number of terms that the `fuzzy` query will expand to.
  43. Defaults to `50`.
  44. WARNING: This query can be very heavy if `prefix_length` is set to `0` and if
  45. `max_expansions` is set to a high number. It could result in every term in the
  46. index being examined!
  47. [float]
  48. ==== Numeric and date fields
  49. Performs a <<query-dsl-range-query>> ``around'' the value using the
  50. `fuzziness` value as a `+/-` range, where:
  51. -fuzziness <= field value <= +fuzziness
  52. For example:
  53. [source,js]
  54. --------------------------------------------------
  55. {
  56. "fuzzy" : {
  57. "price" : {
  58. "value" : 12,
  59. "fuzziness" : 2
  60. }
  61. }
  62. }
  63. --------------------------------------------------
  64. Will result in a range query between 10 and 14. Date fields support
  65. <<time-units,time values>>, eg:
  66. [source,js]
  67. --------------------------------------------------
  68. {
  69. "fuzzy" : {
  70. "created" : {
  71. "value" : "2010-02-05T12:05:07",
  72. "fuzziness" : "1d"
  73. }
  74. }
  75. }
  76. --------------------------------------------------
  77. See <<fuzziness>> for more details about accepted values.