![]() Here is an example of a query for completions of the text “511 Chur”: You can make multiple suggestion queries within a single request, and so you need to give a name to the query. ![]() To request suggestions, you can either specify a “suggestion” section within a normal query, or use the convenient _suggest end-point. For example, to specify “weights” to be used when ranking the suggestions, your document might look like this: ![]() However, if you wish to specify additional information to the suggestion text, then you need to use a longer form. "suggest" : "511 Church St, Richmond, Vic 3121" You can index your suggestions as you would normal Elasticsearch documents: Note that these examples work on Elasticsearch 2, but may need some modifications to work on more recent versions. For example, the following request will create a completion field named “suggest” within a document type called “address” within an index called “address”. To use the completion suggesters, you need to use the special “completion” field type in your index mapping. They are designed to support the prefix matching required by autocompletion more efficiently than the inverted indexes used for normal queries. So typically you would declare the type of a field to be a “string” or “integer” for example, but in this instance we need to use the special “completion” type.Elasticsearch completion suggesters work a little differently to normal Elasticsearch/Lucene inverted indices. I won’t go into the details of what a mapping is except to say it is a bit like a table schema in a relational database. The autosuggest items must be indexed using a document field whose “mapping” has been declared to be a “completion” type. Also, they automatically filter out duplicate results. I will show in later sections how autosuggest can be implemented using standard queries, but you should always consider using a Completion Suggester first as they are faster than standard queries (at least in theory). The Elasticsearch API supports quite complex general searches, but also has specific support for autosuggest in the form of its “ Completion Suggesters“. Like all software that uses Elasticsearch, an autosuggest system needs to interact with Elasticsearch via the Elasticsearch API. For an introduction to these, it is hard to beat the “ Getting Started” chapter of the online “ Elasticsearch Definitive Guide“. While hopefully not essential, it will help if the reader already has some familiarity with Elasticsearch, in particular the concepts of “index”, “index mapping”, and some of the basics of the query DSL. In what follows, I describe several different ways to use Elasticsearch to support autosuggest, starting with simple “completion suggesters” through to more sophisticated queries. All this makes it possible to use Elasticsearch as part of an autosuggest system. It is built on top of Apache Lucene and so it supports a nice range of natural language text analysis options and support for geo-spatial features. For example, would you like “Repetitive Strain Injury” to be a suggestion for “ strai“Įlasticsearch is a document store designed to support fast searches. Do you need to be able to start matching from a word in the middle of the suggestion, or only match from the beginning.Do you want to highlight the matching words.How do you want the suggestions sorted.I will refer to this as “sloppy phrase matching” or just “slopping matching” for short. For example: “Brunswick East” versus “East Brunswick”. Do you wish to allow for minor re-ordering of words.Do you wish to allow for minor misspellings of words (fuzzy matching).There are various important points to consider when implementing autosuggest: In what follows, I will use the the term “autocomplete” in the strict sense of completing what the user has typed so far, and “autosuggest” in the wider sense of suggesting not just completions, but also alternatives that the user may have intended. Autosuggest functionality can help a user fill form input fields by prompting them with likely completions and even alternatives to the text they are typing as they type it. Most of us make use of some sort of autosuggest functionality several times per day to the point of barely even noticing it. In this article I look at several different ways to use Elasticsearch to implement autosuggest.
0 Comments
Leave a Reply. |
AuthorWrite something about yourself. No need to be fancy, just an overview. ArchivesCategories |