fuzzy-query.asciidoc 2.9 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118
  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. GET /_search
  15. {
  16. "query": {
  17. "fuzzy" : { "user" : "ki" }
  18. }
  19. }
  20. --------------------------------------------------
  21. // CONSOLE
  22. Or with more advanced settings:
  23. [source,js]
  24. --------------------------------------------------
  25. GET /_search
  26. {
  27. "query": {
  28. "fuzzy" : {
  29. "user" : {
  30. "value" : "ki",
  31. "boost" : 1.0,
  32. "fuzziness" : 2,
  33. "prefix_length" : 0,
  34. "max_expansions": 100
  35. }
  36. }
  37. }
  38. }
  39. --------------------------------------------------
  40. // CONSOLE
  41. [float]
  42. ===== Parameters
  43. [horizontal]
  44. `fuzziness`::
  45. The maximum edit distance. Defaults to `AUTO`. See <<fuzziness>>.
  46. `prefix_length`::
  47. The number of initial characters which will not be ``fuzzified''. This
  48. helps to reduce the number of terms which must be examined. Defaults
  49. to `0`.
  50. `max_expansions`::
  51. The maximum number of terms that the `fuzzy` query will expand to.
  52. Defaults to `50`.
  53. WARNING: This query can be very heavy if `prefix_length` is set to `0` and if
  54. `max_expansions` is set to a high number. It could result in every term in the
  55. index being examined!
  56. [float]
  57. ==== Numeric and date fields
  58. Performs a <<query-dsl-range-query>> ``around'' the value using the
  59. `fuzziness` value as a `+/-` range, where:
  60. -fuzziness <= field value <= +fuzziness
  61. For example:
  62. [source,js]
  63. --------------------------------------------------
  64. GET /_search
  65. {
  66. "query": {
  67. "fuzzy" : {
  68. "price" : {
  69. "value" : 12,
  70. "fuzziness" : 2
  71. }
  72. }
  73. }
  74. }
  75. --------------------------------------------------
  76. // CONSOLE
  77. Will result in a range query between 10 and 14. Date fields support
  78. <<time-units,time values>>, eg:
  79. [source,js]
  80. --------------------------------------------------
  81. GET /_search
  82. {
  83. "query": {
  84. "fuzzy" : {
  85. "created" : {
  86. "value" : "2010-02-05T12:05:07",
  87. "fuzziness" : "1d"
  88. }
  89. }
  90. }
  91. }
  92. --------------------------------------------------
  93. // CONSOLE
  94. See <<fuzziness>> for more details about accepted values.