Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

What's the difference between search-as-you-type and context suggester?

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?

like image 237
max pleaner Avatar asked Feb 09 '17 03:02

max pleaner


People also ask

What is Elasticsearch suggester?

The term suggester suggests terms based on edit distance. The provided suggest text is analyzed before terms are suggested. The suggested terms are provided per analyzed suggest text token. The term suggester doesn't take the query into account that is part of request.

How does Elasticsearch implement autocomplete?

Autocomplete can be achieved by changing match queries to prefix queries. While match queries work on token (indexed) to token (search query tokens) match, prefix queries (as their name suggests) match all the tokens starting with search tokens, hence the number of documents (results) matched is high.

Did you mean in Elasticsearch?

“Did you mean” is a very important feature in search engines because they help the user by displaying a suggested term so that he can make a more accurate search. To create a “did you mean” we are going to use the Phrase suggester because through it we will be able to suggest sentence corrections and not just terms.


1 Answers

Currently there are 4 types of suggesters in the Elasticsearch:

  • Term suggester. Then one that provide "similar" term, based on the edit distance. It provides suggestions based on data in the index, there are a lot of knobs and turns to tune it.
  • Phrase suggester. It's very similar to what term suggester is doing, but taking into account a whole phrase.
  • Completion suggester or search-as-you-type functionality. If first two are doing something like did you mean functionality or spellchecking, based on the actual terms in the index. This one should "show" you some 5 or 10 relevant docs, while user is typing, and for this one you need to manually index field of suggestion type, where later ES will do a fast lookup.
  • Context suggester. This one is a continuation of the completion suggester, with the idea of the some context where user is coming from (geo) or if engine wants to boost some company over another, just because they are paid for it, or something like this. In this case you also need to manually index additional data.

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.

like image 179
Mysterion Avatar answered Sep 19 '22 21:09

Mysterion