Define and Use Custom Elasticsearch Analyzers

1.5 hours
  • 2 Learning Objectives

About this Hands-on Lab

Relevancy scoring in Elasticsearch is made possible in part by text analyzers. Elasticsearch ships with many analyzers to choose from but has also made it very easy to mix and match tokenizers, token filters, and character filters to create your own analyzer to meet specific text analysis requirements. By using or creating the best analyzer for you, you can greatly improve search results in Elasticsearch. In this hands-on lab, you are given the opportunity to exercise the following:

* Create a custom analyzer based on the “standard” analyzer
* Create a new analyzed field mapping with the custom analyzer
* Reindex documents with the new analyzer to compare search behavior

Learning Objectives

Successfully complete this lab by achieving the following learning objectives:

Create the new index with the custom analyzer and text_entry field.

Use the Kibana console tool to execute the following:

PUT shakespeare_new
{
  "mappings": {
    "properties": {
      "line_id": {
        "type": "integer"
      },
      "line_number": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      },
      "play_name": {
        "type": "keyword"
      },
      "speaker": {
        "type": "keyword"
      },
      "speech_number": {
        "type": "integer"
      },
      "text_entry": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          },
          "case_insensitive": {
            "type": "text",
            "analyzer": "standard_custom"
          }
        }
      },
      "type": {
        "type": "text",
        "fields": {
          "keyword": {
            "type": "keyword",
            "ignore_above": 256
          }
        }
      }
    }
  },
  "settings": {
    "analysis": {
      "analyzer": {
        "standard_custom": {
          "type": "custom",
          "tokenizer": "standard"
        }
      }
    },
    "number_of_shards": 4,
    "number_of_replicas": 3
  }
}
Reindex the data from shakespeare into shakespeare_new.

Use the Kibana console tool to execute the following:

POST _reindex
{
  "source": {
    "index": "shakespeare"
  },
  "dest": {
    "index": "shakespeare_new"
  }
}

Additional Resources

You work as an Elasticsearch administrator who manages a 6-node Elasticsearch cluster that is being used for literary research. The research librarians who are currently using your cluster, to study the works of Shakespeare, have requested the addition of a new search behavior. Currently, the multi-field text_entry is indexed as both a non-analyzed keyword field and an analyzed text field using the standard analyzer. They are requesting the addition of another text_entry field called text_entry.case_insensitive that is also an analyzed text field, but analyzed with a custom analyzer called standard_custom that behaves exactly as the standard analyzer but does not lowercase the resulting words. For example, the line "Death, death; O amiable lovely death!" is analyzed by the standard analyzer as [death, death, o, amiable, lovely, death] but should be analyzed by the custom analyzer as [Death, death, O, amiable, lovely, death].

The new field mapping and custom analyzer should be created on a new index called shakespeare_new which should otherwise look exactly like the shakespeare index. Once the index has been created with the requirements explained above, you will need to reindex the documents from the shakespeare index into the shakespeare_new index.

To use Kibana, navigate to the public IP address of the coordinator-1 node in your web browser and login with:

  • Username: elastic
  • Password: la_elastic_409
What are Hands-on Labs

Hands-on Labs are real environments created by industry experts to help you learn. These environments help you gain knowledge and experience, practice without compromising your system, test without risk, destroy without fear, and let you learn from your mistakes. Hands-on Labs: practice your skills before delivering in the real world.

Get Started
Who’s going to be learning?

How many seats do you need?

  • $499 USD per seat per year
  • Billed Annually
  • Renews in 12 months

Ready to accelerate learning?

For over 25 licenses, a member of our sales team will walk you through a custom tailored solution for your business.


$2,495.00

Checkout
Sign In
Welcome Back!
Thanks for reaching out!

You’ll hear from us shortly. In the meantime, why not check out what our customers have to say about ACG?