Sohan
Sohan

Reputation: 3807

Elastic Search - implement "Did you Mean"

We are trying to use Elastic Search in a Rails app and would like any input/code example on the implementation of "did you mean" feature. Essentially, we want to provide the end user an option to search for an alternate query like in google.

Upvotes: 12

Views: 9319

Answers (3)

mst
mst

Reputation: 466

You can use fuzzy search:

"fuzzy" : {
    "user" : {
        "value" :         "Jon",
        "boost" :         1.0,
        "fuzziness" :     3,
        "prefix_length" : 0,
        "max_expansions": 100
    }
}

Check this link for fuzzy : http://www.elasticsearch.org/guide/en/elasticsearch/reference/current/query-dsl-fuzzy-query.html

Upvotes: 1

Simon Steinberger
Simon Steinberger

Reputation: 6825

As of version 0.90.0.Beta1, ElasticSearch has a "term suggest" feature included, which is what you are looking for:

http://www.elasticsearch.org/guide/reference/api/search/term-suggest/

E.g. get from this query: "devloping distibutd saerch engies" this result: "developing distributed search engines"

Upvotes: 9

Ian
Ian

Reputation: 379

Elasticsearch doesn't have it yet, it is opened as issue here basically it is waiting for the next Lucene release.

I achieved a similar "did you mean" behaviour using the phonetic analyzers, which worked for my use case, location names, that is not gonna work for all use cases....

a example mapping:- https://gist.github.com/1171014

so you can query using the REST api like this (mispelled london):-

{
  "query": {
    "field": {
      "nameSounds": "lundon"
    }
  }
}

Upvotes: 7

Related Questions