Suggester12/11/2023 ![]() ![]() Most of the hard work is abstracted away, but you still get a lot of control over the results by tweaking the numerous parameters the query accepts. ![]() The Elasticsearch suggest functionality is a really powerful and versatile tool. As noted in the documentation for this parameter, setting this value too high will negatively impact performance. Setting this parameter to 2 could be useful if the input contains multiple terms most of the time. You can increase this by setting the max_errors parameter to 2 or more, or to a fraction of the input term count (for example setting it to 0.5 will allow 50% of the terms to be corrected). few or no results), or based on the score that is returned.īy default, the suggestions will correct at most one term. Lower values make sense if you want to determine whether to show suggestions to users based on your own logic (e.g. ![]() The default value of 1.0 is sensible if you are going for functionality that will automatically change user input. If we find a suggestion that matches, we replace the current search term with the suggestion and execute the search query again.ĭepending on your use case, you may want to play with the confidence parameter. In the example, we only run this suggest query when no results are returned from the search query. We can now filter out options based on collate_match. For most cases, a sensible analyzer would be set up like this:Įnter fullscreen mode Exit fullscreen mode It can use the shingled representation of the data to determine how common the corrected words appear next to each other.ĭepending on how you configure the shingle filter, the suggester will be able to suggest shorter or longer sentences. To take the context into account, the Phrase Suggester uses a shingled version of the specified field to be able to suggest combinations of terms correctly. If a user now searches for "harry poter", you do know which suggestion to give: "Potter". Without context, you don't know which one is better though. If a user now searches for "poter", you could correct that to either "Potter" or "poster". The Phrase Suggester will then combine these suggestions in a smart way into a single correction for the whole input.įor example, imagine you have a document with the text "Harry Potter poster". Each of these generators will generate suggestions for a single term. To get the Phrase Suggester to work, we'll need to supply it with a list of generators. Today we are going to use the Phrase Suggester to find search terms that are related to some input search terms. Users are likely to be at least annoyed when presented with no results, and in many cases they might give up their search for something completely.Įlasticsearch provides an extensive suggest feature which allows you to autocomplete user input. This hurts the user directly, as they will either need to fix their search term, or will think that the item they are looking for simply is not available. The worst thing you can do is show no results when you actually have some idea of what results to show. If you want to try it out yourself, check out this example repo. This post shows you how to find corrected search terms in Elasticsearch using the suggester query type, and how to apply this in an effective way. ![]() Only so much can be solved by optimizing the matching of your search query. You probably know how Google handles these situations: The search engine suggests a corrected search term, or even automatically corrects the terms you searched for if nothing could be found. ![]()
0 Comments
Leave a Reply.AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |