Appendix F. Using suggesters for autocomplete and did-you-mean functionality

You now expect search engines not only to return good results but also to improve your queries. Take Google, for instance: if you make a typo, Google tells you about it and recommends a correction or even runs it directly, as shown in figure F.1.

Figure F.1. Spell checking by Google

Google also tries to prevent typos by offering autocomplete, which also makes queries faster and shows you topics that you might find interesting, as shown in figure F.2.

Figure F.2. Autocomplete on Google

Elasticsearch offers both did-you-mean (DYM) and autocomplete functionality through the Suggesters module. The point of a suggester is to take a given text and return better keywords.

In this appendix we’ll cover four types of suggesters:

Term suggester— For each term in the provided text, it suggests keywords from the index. It works well for DYM on short fields, such as tags.

Phrase suggester— You can think of it as an extension of the term suggester that provides DYM alternatives for the whole text instead of individual terms. It accounts for how often terms appear next to each other, making it especially better for longer fields, such as product descriptions.

Completion Suggester— This provides autocomplete functionality based on term prefixes. It works with in-memory structures, making it faster than the prefix queries you saw in chapter 4. Context Suggester— This is an extension of the Completion Suggester that allows you to filter alternatives based on terms (categories) or geo-point locations.

Note

Work is being done on a new suggester based on the NRT suggester. More options will be included like geo distance and filters. This new suggester is planned for version 2.0; the current suggesters will keep working as described here. More information on the new suggester can be found here: https://github.com/elastic/elasticsearch/issues/8909.