WARNING: Version 2.3 of Elasticsearch has passed its EOL date.
This documentation is no longer being maintained and may be removed. If you are running this version, we strongly advise you to upgrade. For the latest information, see the current release documentation.
Fuzzy Query
editFuzzy Query
editThe fuzzy query uses similarity based on Levenshtein edit distance for
string
fields, and a +/-
margin on numeric and date fields.
String fields
editThe fuzzy
query generates all possible 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.
Here is a simple example:
{ "fuzzy" : { "user" : "ki" } }
Or with more advanced settings:
{ "fuzzy" : { "user" : { "value" : "ki", "boost" : 1.0, "fuzziness" : 2, "prefix_length" : 0, "max_expansions": 100 } } }
Parameters
edit
|
The maximum edit distance. Defaults to |
|
The number of initial characters which will not be “fuzzified”. This
helps to reduce the number of terms which must be examined. Defaults
to |
|
The maximum number of terms that the |
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!
Numeric and date fields
editPerforms a Range Query “around” the value using the
fuzziness
value as a +/-
range, where:
-fuzziness <= field value <= +fuzziness
For example:
{ "fuzzy" : { "price" : { "value" : 12, "fuzziness" : 2 } } }
Will result in a range query between 10 and 14. Date fields support time values, eg:
{ "fuzzy" : { "created" : { "value" : "2010-02-05T12:05:07", "fuzziness" : "1d" } } }
See Fuzziness for more details about accepted values.