Reader small image

You're reading from  Elasticsearch Indexing

Product typeBook
Published inDec 2015
Publisher
ISBN-139781783987023
Edition1st Edition
Right arrow
Author (1)
Huseyin Akdogan
Huseyin Akdogan
author image
Huseyin Akdogan

Hüseyin Akdoğan began his software adventure with the GwBasic programming language. He started learning the Visual Basic language after QuickBasic and developed many applications until 2000, after which he stepped into the world of Web with PHP. After this, he came across Java! In addition to counseling and training activities since 2005, he developed enterprise applications with JavaEE technologies. His areas of expertise are JavaServer Faces, Spring Frameworks, and big data technologies such as NoSQL and Elasticsearch. Along with these, he is also trying to specialize in other big data technologies. Hüseyin also writes articles on Java and big data technologies and works as a technical reviewer of big data books. He was a reviewer of one of the bestselling books, Mastering Elasticsearch – Second Edition.
Read more about Huseyin Akdogan

Right arrow

Chapter 8. Improving the User Search Experience

In the previous chapter, we looked at how to back up and restore our data. We examined the snapshot repository and snapshot/restore process functionality. We talked about configuration details to snapshot and restore. Finally, we discussed how the snapshot process works and the form of snapshot files. In this chapter, we will examine the Elasticsearch Suggest API to correct user's spelling mistakes and we will look closely at the various functionalities provided by Elasticsearch to improve the relevancy of search results. By the end of this chapter, we will have covered:

  • How to correct user's spelling mistakes

  • How to use the term suggester

  • How to use the phrase suggester

  • How to provide the autocomplete functionality for the user

  • How to use boosting

  • How to use synonyms

Correction of users' spelling mistakes


Typos and spelling mistakes are often encountered due to many reasons. Therefore, correcting typos and user spelling mistakes is an integral part of a good search experience. When you search for a phrase that is close to another frequently searched phrase, you may see the did you mean phrase, which helps correct users' spelling mistakes, as search engines use this form to improve the user search experience. For such a case, this is what Google shows us when we type in threat safe instead of thread safe. Take a look at the following screenshot as an example:

Elasticsearch allows us to use the Suggest API functionality. In this section, we will look at how to use the Suggest API both in simple use case scenarios and the basic configuration settings.

Suggesters

The Suggest API suggests similar terms based on text that you provided by using a suggester. Elasticsearch allows us to use three suggesters that provide three different functionalities. These are...

Get suggestions


If we would like to find documents that have directors starting with tar, we would run the following command:

curl -XGET localhost:9200/imdb/_suggest?pretty -d '{
 "directorAutocomplete": {
  "text": "tar",
  "completion": {
   "field": "completion_suggest"
  }
 }
}'

The result returned by Elasticsearch for the preceding query looks as follows:

{
   "_shards": {
      "total": 5,
      "successful": 5,
      "failed": 0
   },
   "directorAutocomplete": [
      {
         "text": "tar",
         "offset": 0,
         "length": 3,
         "options": [
            {
               "text": "Andrei Arsenyevich Tarkovsky",
               "score": 1,
               "payload": {
                  "movies": [
                     "Ivan's Childhood",
                     "Andrei Rublev",
                     "Solaris",
                     "The Mirror",
                     "Stalker",
                     "Nostalgia",
                     "The Sacrifice"
                  ]
      ...

Improving the relevancy of search results


In general, Elasticsearch is used for searching while it is a data analysis tool. In this respect, improving query relevance is an important issue. Of course, searching also means querying and scoring, thus it is a very important part of querying in Apache Lucene as well. We can use the re-scoring mechanism to improve the query's relevance. In addition to the capabilities of document scoring in the Apache Lucene library, Elasticsearch provides different query types to manipulate the score of the results returned by our queries. In this section, you will find several tips on this issue.

Boosting the query

Boosting queries allows us to effectively demote results that match a given query. This feature is very useful in that we can send some irrelevant records of the result set to the back. For example, we have an index that stores the skills of developers and we're looking for developers who know the Java language. We use a query such as the following...

Summary


In this chapter, we looked at the Suggest API and saw how we can use term, phrase, and completion suggesters with their configuration details. Then, we looked at the various functionalities to improve the relevancy of search results provided by Elasticsearch. We looked at how we can broaden the scope of matching documents with the synonym facility. Finally, we tried to correctly understand the notion of the _all field in depth.

Thank you for reading this book. We hope that you liked it and that we have reinforced your knowledge of effective indexing, which can adeptly help you to improve the relevancy of search results using Elasticsearch.

lock icon
The rest of the chapter is locked
You have been reading a chapter from
Elasticsearch Indexing
Published in: Dec 2015Publisher: ISBN-13: 9781783987023
Register for a free Packt account to unlock a world of extra content!
A free Packt account unlocks extra newsletters, articles, discounted offers, and much more. Start advancing your knowledge today.
undefined
Unlock this book and the full library FREE for 7 days
Get unlimited access to 7000+ expert-authored eBooks and videos courses covering every tech area you can think of
Renews at $15.99/month. Cancel anytime

Author (1)

author image
Huseyin Akdogan

Hüseyin Akdoğan began his software adventure with the GwBasic programming language. He started learning the Visual Basic language after QuickBasic and developed many applications until 2000, after which he stepped into the world of Web with PHP. After this, he came across Java! In addition to counseling and training activities since 2005, he developed enterprise applications with JavaEE technologies. His areas of expertise are JavaServer Faces, Spring Frameworks, and big data technologies such as NoSQL and Elasticsearch. Along with these, he is also trying to specialize in other big data technologies. Hüseyin also writes articles on Java and big data technologies and works as a technical reviewer of big data books. He was a reviewer of one of the bestselling books, Mastering Elasticsearch – Second Edition.
Read more about Huseyin Akdogan