AI Hints
Home›Elasticsearch Tutorial›Project: Trailhead Search
Elasticsearch · Lesson 115 of 120

Project: Trailhead Search

The mapping.

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

Time to build Trailhead's real product search, using everything from this course. Part one is the mapping. Part two, search and facets. Part three, autocomplete and ranking.

  • 1. Mapping
  • 2. Search + facets
  • 3. Autocomplete + ranking

The project mapping

An edge n gram analyzer powers autocomplete. Name uses the english analyzer, with an autocomplete subfield, and a keyword subfield for sorting. Brand and category are keywords for facets, and price and rating are numbers. Reindex copies all the products in. Run it. Forty nine products, in a mapping built for search.

Dev Tools Consoletext
PUT trailhead?filter_path=acknowledged
{ "settings": { "analysis": {
    "filter": { "edge": { "type": "edge_ngram", "min_gram": 2, "max_gram": 10 } },
    "analyzer": { "auto": { "tokenizer": "standard", "filter": ["lowercase", "edge"] } } } },
  "mappings": { "properties": {
    "name": { "type": "text", "analyzer": "english", "fields": {
      "auto": { "type": "text", "analyzer": "auto", "search_analyzer": "standard" },
      "keyword": { "type": "keyword" } } },
    "description": { "type": "text", "analyzer": "english" },
    "brand":    { "type": "keyword" }, "category": { "type": "keyword" },
    "price":    { "type": "double" },  "rating":   { "type": "double" },
    "in_stock": { "type": "boolean" } } } }

POST _reindex?refresh=true&filter_path=created
{ "source": { "index": "products" }, "dest": { "index": "trailhead" } }
Output
# PUT trailhead 200 OK
{"acknowledged": true}

# POST _reindex 200 OK
{"created": 49}
Also uses _load
products

Why each choice

English analysis means jackets matches jacket. The auto subfield gives instant prefixes. Keywords make exact filters and facets fast. And numbers allow ranges and sorting.

keyvalue
name (english)stems match
name.autoautocomplete
brand, categoryfilters, facets
price, ratingranges, sorting

Summary

The project mapping covers full text, autocomplete, facets and numbers. Next, the search request with facets.

Key takeaways
  • Analyzers
  • Subfields
  • Reindex
Next up: Project: Search and Facets — the main search