OpenSearch/docs/reference/query-dsl/fuzzy-query.asciidoc

76 lines
1.7 KiB
Plaintext
Raw Normal View History

[[query-dsl-fuzzy-query]]
=== Fuzzy Query
The fuzzy query uses similarity based on Levenshtein edit distance.
==== String fields
The `fuzzy` query generates matching terms that are within the
maximum edit distance specified in `fuzziness` and then checks the term
dictionary to find out which of those generated terms actually exist in the
index. The final query uses up to `max_expansions` matching terms.
Here is a simple example:
[source,js]
--------------------------------------------------
GET /_search
{
"query": {
"fuzzy" : { "user" : "ki" }
}
}
--------------------------------------------------
// CONSOLE
Or with more advanced settings:
[source,js]
--------------------------------------------------
GET /_search
{
"query": {
"fuzzy" : {
"user" : {
2018-01-01 02:44:04 -05:00
"value": "ki",
"boost": 1.0,
"fuzziness": 2,
"prefix_length": 0,
"max_expansions": 100
}
}
}
}
--------------------------------------------------
// CONSOLE
[float]
===== Parameters
[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.
Defaults to `50`.
`transpositions`::
Whether fuzzy transpositions (`ab` -> `ba`) are supported.
Default is `true`.
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!