fuzzy-query.asciidoc 2.6 KB

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