fuzzy-query.asciidoc 2.3 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` and `max_expansions`
  45. are both set to `0`. This could cause every term in the index to be examined!
  46. [float]
  47. ==== Numeric and date fields
  48. Performs a <<query-dsl-range-query>> ``around'' the value using the
  49. `fuzziness` value as a `+/-` range, where:
  50. -fuzziness <= field value <= +fuzziness
  51. For example:
  52. [source,js]
  53. --------------------------------------------------
  54. {
  55. "fuzzy" : {
  56. "price" : {
  57. "value" : 12,
  58. "fuzziness" : 2
  59. }
  60. }
  61. }
  62. --------------------------------------------------
  63. Will result in a range query between 10 and 14. Date fields support
  64. <<time-units,time values>>, eg:
  65. [source,js]
  66. --------------------------------------------------
  67. {
  68. "fuzzy" : {
  69. "created" : {
  70. "value" : "2010-02-05T12:05:07",
  71. "fuzziness" : "1d"
  72. }
  73. }
  74. }
  75. --------------------------------------------------
  76. See <<fuzziness>> for more details about accepted values.