Reputation: 26788
I want to implement search-as-you-type (i.e. autosuggest in a search input) and it seems there are at least two doc pages with different approaches to do this:
https://www.elastic.co/guide/en/elasticsearch/guide/2.x/_index_time_search_as_you_type.html
https://www.elastic.co/guide/en/elasticsearch/reference/current/suggester-context.html
Am I right that with suggester, I manually provide records for the suggestion index whereas in the search-as-you-type, I'm using the existing index data? Why would I choose one over the other?
Upvotes: 15
Views: 16874
Reputation: 339
This is a table a made for myself after investigating the best way to implement autocomplete for our app:
differentiate between Query Suggestion and Search
UseCase | Completion S. | Context S. | Term S. | Phrase S. | search_as_you_type | Edge N-Gram |
---|---|---|---|---|---|---|
Basic Auto-Complete | X | X | X | X | ||
Flexible Search/Query | X | X | ||||
High Performace for Large Datasets | X | X | X | X | ||
Higher Memory Usage | X | X | X | |||
Higher Storage Usage | X | X | ||||
Substring Matches | X | X | ||||
Dynamic Data Updates | X | X | X | X | ||
Relevance Scoring | X | X | X | X | ||
Spell Correction | X | X | ||||
complexity to implement | low | high | medium | high | low | medium |
Speciality | fast prefix matching | context-aware suggestions | single term corrections | multi term corrections | implements edge n-gram, full text partial matching |
Upvotes: 2
Reputation: 9320
Currently there are 4 types of suggesters in the Elasticsearch:
UPD. Starting from Elasticsearch 7.2 there was introduced search-as-you-type field type, which isn't a suggester per-se, but provides capabilities for simulating search-as-you-type functionality.
It creates a series of subfields that are analyzed to index terms that can be efficiently matched by a query that partially matches the entire indexed text value. Both prefix completion (i.e matching terms starting at the beginning of the input) and infix completion (i.e. matching terms at any position within the input) are supported.
Regarding your question: in principal in both cases, you need to index something (there is no magic in Elasticsearch), but first two suggesters are more did you mean corrections, spellchecking corrections, while two later are requiring additional indexing. First two, are just normal data structures, you could use them for normal search or for these suggesters, while last two are build to be super-fast, they use data structures that enable fast lookups, but are costly to build and are stored in-memory.
So, your choice should come from your use-cases and never forget the overhead you had in both cases.
Upvotes: 39