AI Hints
Home›Elasticsearch Tutorial›Templates and Strict Mappings
Elasticsearch · Lesson 51 of 120

Practice: Design the Catalog Mapping

Every field, the right type.

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

Let's design the real mapping for the Trailhead catalog. For each field, ask, will people search it as words, or filter, sort and count it?

  • Searched as words?
  • Filtered or sorted?
  • Pick the type

The catalog mapping

Name and description are text. Name also gets a keyword, for sorting. Brand, category, tags and colors are keywords, for filters. Numbers and dates get their types. Run it. This is the mapping we'll use from now on.

Dev Tools Consoletext
PUT products
{ "mappings": { "dynamic": "strict", "properties": {
  "id":          { "type": "integer" },
  "name":        { "type": "text", "fields": { "keyword": { "type": "keyword" } } },
  "description": { "type": "text" },
  "brand":       { "type": "keyword" },  "category": { "type": "keyword" },
  "tags":        { "type": "keyword" },  "colors":   { "type": "keyword" },
  "price":       { "type": "double" },   "rating":   { "type": "double" },
  "reviews":     { "type": "integer" },  "in_stock": { "type": "boolean" },
  "added":       { "type": "date" },     "weight_g": { "type": "integer" } } } }
Output
{
  "acknowledged": true,
  "shards_acknowledged": true,
  "index": "products"
}

Design checklist

Words people type, use text. Values people click, like brands and colors, use keyword. Things you sort alphabetically need a keyword too. And set dynamic to strict, so surprises fail fast.

keyvalue
Typed wordstext
Clicked filterskeyword
Sorted names+ keyword sub-field
Safetydynamic: strict

Summary

A good mapping decides, for every field, text or keyword, and the right number and date types. Next, analysis, how text becomes searchable words.

Key takeaways
  • text or keyword
  • Right types
  • strict
Next up: How Analysis Works — from text to terms