2013-08-28 19:24:34 -04:00
|
|
|
[[query-dsl-fuzzy-query]]
|
2019-07-18 10:18:11 -04:00
|
|
|
=== Fuzzy query
|
|
|
|
++++
|
|
|
|
<titleabbrev>Fuzzy</titleabbrev>
|
|
|
|
++++
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2016-05-11 04:28:42 -04:00
|
|
|
The fuzzy query uses similarity based on Levenshtein edit distance.
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2015-06-03 19:59:22 -04:00
|
|
|
==== String fields
|
2014-01-02 10:45:24 -05:00
|
|
|
|
2018-07-30 15:48:14 -04:00
|
|
|
The `fuzzy` query generates matching terms that are within the
|
2014-01-02 10:45:24 -05:00
|
|
|
maximum edit distance specified in `fuzziness` and then checks the term
|
|
|
|
dictionary to find out which of those generated terms actually exist in the
|
2018-07-30 15:48:14 -04:00
|
|
|
index. The final query uses up to `max_expansions` matching terms.
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
Here is a simple example:
|
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
2016-05-24 05:58:43 -04:00
|
|
|
GET /_search
|
2013-08-28 19:24:34 -04:00
|
|
|
{
|
2016-05-24 05:58:43 -04:00
|
|
|
"query": {
|
|
|
|
"fuzzy" : { "user" : "ki" }
|
|
|
|
}
|
2013-08-28 19:24:34 -04:00
|
|
|
}
|
|
|
|
--------------------------------------------------
|
2016-05-24 05:58:43 -04:00
|
|
|
// CONSOLE
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2014-01-02 10:45:24 -05:00
|
|
|
Or with more advanced settings:
|
2013-08-28 19:24:34 -04:00
|
|
|
|
|
|
|
[source,js]
|
|
|
|
--------------------------------------------------
|
2016-05-24 05:58:43 -04:00
|
|
|
GET /_search
|
2014-01-02 10:45:24 -05:00
|
|
|
{
|
2016-05-24 05:58:43 -04:00
|
|
|
"query": {
|
|
|
|
"fuzzy" : {
|
|
|
|
"user" : {
|
2018-01-01 02:44:04 -05:00
|
|
|
"value": "ki",
|
|
|
|
"boost": 1.0,
|
|
|
|
"fuzziness": 2,
|
|
|
|
"prefix_length": 0,
|
|
|
|
"max_expansions": 100
|
2016-05-24 05:58:43 -04:00
|
|
|
}
|
2013-08-28 19:24:34 -04:00
|
|
|
}
|
|
|
|
}
|
2014-01-02 10:45:24 -05:00
|
|
|
}
|
2013-08-28 19:24:34 -04:00
|
|
|
--------------------------------------------------
|
2016-05-24 05:58:43 -04:00
|
|
|
// CONSOLE
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2014-01-02 10:45:24 -05:00
|
|
|
[float]
|
2015-06-03 19:59:22 -04:00
|
|
|
===== Parameters
|
2014-01-02 10:45:24 -05:00
|
|
|
|
|
|
|
[horizontal]
|
|
|
|
`fuzziness`::
|
|
|
|
|
|
|
|
The maximum edit distance. Defaults to `AUTO`. See <<fuzziness>>.
|
|
|
|
|
|
|
|
`prefix_length`::
|
|
|
|
|
|
|
|
The number of initial characters which will not be ``fuzzified''. This
|
|
|
|
helps to reduce the number of terms which must be examined. Defaults
|
|
|
|
to `0`.
|
|
|
|
|
|
|
|
`max_expansions`::
|
|
|
|
|
|
|
|
The maximum number of terms that the `fuzzy` query will expand to.
|
2014-05-13 10:12:05 -04:00
|
|
|
Defaults to `50`.
|
2014-01-02 10:45:24 -05:00
|
|
|
|
2017-10-05 03:01:09 -04:00
|
|
|
`transpositions`::
|
|
|
|
|
|
|
|
Whether fuzzy transpositions (`ab` -> `ba`) are supported.
|
2017-10-11 09:31:48 -04:00
|
|
|
Default is `true`.
|
2014-01-02 10:45:24 -05:00
|
|
|
|
2015-10-13 15:03:46 -04:00
|
|
|
WARNING: This query can be very heavy if `prefix_length` is set to `0` and if
|
|
|
|
`max_expansions` is set to a high number. It could result in every term in the
|
|
|
|
index being examined!
|
2013-08-28 19:24:34 -04:00
|
|
|
|
2016-05-24 05:58:43 -04:00
|
|
|
|