AI Hints
Home›Elasticsearch Tutorial›Normalizers and Autocomplete
Elasticsearch · Lesson 58 of 120

Normalizers

Tidy keywords.

⏱ 2 min read▶ Video at 54:44🎓 Free
Watch this lesson in the Elasticsearch courseWatch on YouTube ↗Full Elasticsearch course

Keyword fields are exact, so Summit and summit are different brands. When data comes from many suppliers, the case is a mess. A normalizer cleans keywords without splitting them.

  • Summit vs summit
  • Exact values
  • Normalizer

A lowercase normalizer

The normalizer lower cases and folds accents. Brand uses it. We index SUMMIT in capitals, and filter for summit. Run it. The term query now matches, whatever the case.

Dev Tools Consoletext
PUT products
{ "settings": { "analysis": { "normalizer": { "tidy": {
    "type": "custom", "filter": ["lowercase", "asciifolding"] } } } },
  "mappings": { "properties": {
    "brand": { "type": "keyword", "normalizer": "tidy" } } } }

PUT products/_doc/1?refresh=true&filter_path=result
{ "brand": "SUMMIT" }

GET products/_count?filter_path=count
{ "query": { "term": { "brand": "summit" } } }
Output
# PUT products 200 OK
{
  "acknowledged": true,
  "shards_acknowledged": true,
  "index": "products"
}

# PUT products/_doc/1 201 Created
{"result": "created"}

# GET products/_count 200 OK
{"count": 1}

Normalizer or analyzer?

An analyzer splits text into many terms. A normalizer keeps one term, and only cleans it. So normalizers can't use tokenizers, only filters that work one character at a time. Sorting and aggregations still work.

keyvalue
Analyzermany terms
Normalizerone clean term
Allowedlowercase, asciifolding
Still workssort, aggregate

Summary

A normalizer cleans keyword values, like lower casing, while keeping each value as one term. Next, autocomplete.

Key takeaways
  • normalizer
  • keyword
  • Case-insensitive
Next up: Autocomplete with Edge N-grams — results as you type