11

Is there a standard way to implement character-by-character typeahead autocomplete using ElasticSearch for small fields (e.g. place names).

(At the time of writing this, there are a number of discussions available via search, but nothing that seems definitive. (Also, I see there is talk of the effect of feature support for autocomplete/suggest in Apache Lucene 4.))

Thanks for thoughts.

3 Answers 3

9

You can use Edge NGram based analyzer, see http://www.elasticsearch.org/guide/reference/index-modules/analysis/edgengram-tokenizer.html

Or use the suggest plugin: https://github.com/spinscale/elasticsearch-suggest-plugin

HTH

Sign up to request clarification or add additional context in comments.

Comments

3

As David wrote, you can use NGrams or the suggest plugin. With lucene 4 it will be possible to have better auto-suggestions out-of-the-box, without the need to mantain a separate index.

For now you can also just make a terms facet on your field and use a regex pattern to keep only the entries that start with the relevant prefix:

"facets" : {
    "tag" : {
        "terms" : {
            "field" : "field_name",
            "regex" : "prefix.*"
        }
    }
}

The regex is just an example, it can be improved and you can also make it case insensitive using the proper regex flag. Also, beware that making on a facet on a field that contains many unique terms is not a great idea, unless you have enough memory for it.

Comments

3

Use the built-in autocompletion suggester that's available since version 0.90.3:

http://www.elastic.co/guide/en/elasticsearch/reference/master/search-suggesters-completion.html

It's blazingly fast and was developed for exactly that use case.

4 Comments

BTW @simon the new completion prefix suggestion feature is not at 0.90.0 but in 0.90.3 (and still considered experimental). github.com/elasticsearch/elasticsearch/issues/3376
True is very fast, but is the same thing than use mySQL LIKE prefix* or Redis/CouchBase auto-complete.
The link in the answer no more exists. This may be a help for newbies! elastic.co/guide/en/elasticsearch/reference/master/…
Updated documentation link and text.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.