Fuzzy lookup for query string on ElasticSearch

elasticsearch, fuzzy-search, query-string

Solution

You can either use the fuzzy query:

{
    "fuzzy" : { "user" : "ki" }
}

Or use the `fuzziness` factor in a `match` query. Another way to achieve what you want in your example is to use synonyms. With synonyms you can tell elasticsearch to store synonyms to your words along with the original words, e.g. gray will be stored as gray and grey.

Here is a in-depth description of the synonyms: http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/analysis-synonym-tokenfilter.html

Problem

I'm using ElasticSearch for letting users search through text fields, consisting of joined tag strings. The query looks like this and it works nicely: ``` { 'query' : { 'query_string' : { 'query' : 'user query with +bool AND operators', 'default_operator' : 'AND', 'fields' : ['tag_string'], 'analyzer' : 'my_analyzer' } } } ``` However, I'd like to enable fuzzy matching so that British English and American spelling are covered. E.g. I'd like to get the same results for "gray" and "grey" or for "color" and "colour". This can be done by the user by using the fuzzy operator "~" - so searching for "color~" matches both "color" and "colour". But that should be done automatically ... yet, the search query may contain bool operators and thus, may be complex.

Original source