Skip to main content
PreparationZone Logo
PrepZone

Elasticsearch CRUD and Mapping

Index documents, dynamic vs explicit mapping, and keyword vs text fields.

Pass checkpoint below

Why this matters

  • VaultCommerce product SKUs must be keyword (exact match, aggregations); descriptions must be text (analyzed for search). Swapping them breaks faceted filters and full-text queries.
  • Bulk indexing during catalog sync needs the _bulk API — single-document PUTs cannot keep up with nightly imports.
  • Mapping mistakes (e.g., price mapped as text) require reindex — expensive at millions of documents.
Cluster
Node 1Shard 0 primary
Node 2Shard 1 primary
Node 3Shard 0 replica
An index is split into shards across nodes. Replicas provide failover and read scaling.

Explicit mapping for products

Java
curl -X PUT "localhost:9200/vaultcommerce-products" -H 'Content-Type: application/json' -d'
{
  "mappings": {
    "properties": {
      "sku":        { "type": "keyword" },
      "title":      { "type": "text", "fields": { "raw": { "type": "keyword" } } },
      "description":{ "type": "text" },
      "category":   { "type": "keyword" },
      "price":      { "type": "float" },
      "in_stock":   { "type": "boolean" },
      "tags":       { "type": "keyword" }
    }
  }
}'

keyword vs text

  • keyword — stored as-is for filters, sorting, aggregations (SKU, category).
  • text — analyzed (tokenized, lowercased) for full-text search (title, description).
  • Multi-fields — title.raw keyword sub-field for exact sort while title remains searchable.

Dynamic mapping works for prototypes; VaultCommerce locks mapping before production indexing.

The rest of this guide is part of Pro

Free covers every fresher guide in full. Pro unlocks Senior, Staff and Architect guides across every track.

Still to come · 2 sections

  • CRUD operations
  • Bulk import for catalog sync

Test yourself

Answer these before moving on — recall is what makes it stick.