100% Free Forever
AI-Powered Learning
Industry Expert Content
Certificates & Badges
Learn At Your Own Pace
Elasticsearch

Mapping Types Explained

Understand the core Elasticsearch field data types, text vs keyword, numbers, dates, and objects, and how each shapes search behavior.

IndexingIntermediate9 min readJul 10, 2026
Analogies

Why Field Types Matter

A mapping defines, field by field, how Elasticsearch stores and indexes each piece of a document, and that choice directly determines what kinds of queries will work correctly against it. Choosing the wrong type is one of the most common production mistakes, for example mapping a numeric ID as text means range queries silently return wrong results because the field is analyzed and compared lexicographically rather than numerically.

🏏

Cricket analogy: Recording a bowler's speed as text like 'one forty two' instead of a number means you can never sort deliveries by pace, just as mapping a numeric field as text breaks range queries.

Text vs Keyword: The Most Important Distinction

The text type is analyzed at index time, meaning the value is lowercased, tokenized into individual terms, and often stemmed, which makes it suited for full-text search like matching 'running shoes' against a product description. The keyword type, by contrast, is stored exactly as-is with no analysis, making it suited for exact matches, sorting, aggregations, and filters, such as matching a status field to exactly 'shipped'.

🏏

Cricket analogy: Commentary transcripts get broken into searchable phrases like text analysis breaking a sentence into terms, while a player's exact squad number like '18' for Virat Kohli must match precisely like a keyword field.

json
{
  "mappings": {
    "properties": {
      "description": { "type": "text" },
      "status": { "type": "keyword" },
      "title": {
        "type": "text",
        "fields": {
          "raw": { "type": "keyword" }
        }
      }
    }
  }
}

The multi-field pattern shown above, mapping title as text with a title.raw keyword sub-field, is extremely common: it lets you full-text search title while still sorting or aggregating on title.raw.

Numeric, Date, and Boolean Types

Elasticsearch offers several numeric types, long, integer, short, byte, double, float, half_float, and scaled_float, and picking the narrowest type that fits your data saves disk space and speeds up aggregations across large datasets. The date type accepts strings in a configurable format, defaulting to strict_date_optional_time, and stores dates internally as milliseconds since the epoch, which is why date range queries and date histogram aggregations are fast even across millions of documents.

🏏

Cricket analogy: A scorecard app storing 'overs bowled' as a small byte-range number since it never exceeds 50, rather than a bulky long, mirrors picking the narrowest numeric type that still fits the data.

Changing a field's type after data has already been indexed is not supported in place; Elasticsearch will reject conflicting documents or silently coerce values depending on settings. If you need a different type, you must reindex into a new index with the corrected mapping.

  • A mapping controls how each field is stored and indexed, which directly determines which queries work correctly.
  • Use text for analyzed, full-text-searchable fields and keyword for exact-match, sortable, aggregatable fields.
  • The multi-field pattern (text with a keyword sub-field) lets one field support both search and aggregation.
  • Choose the narrowest numeric type, byte through double, that realistically fits your data's range.
  • Dates are stored internally as milliseconds since epoch, making range queries and histograms fast.
  • Field types cannot be changed in place after data is indexed; a reindex into a new index is required.
  • Mis-typing a numeric field as text silently breaks range queries and sorts lexicographically instead.

Practice what you learned

Was this page helpful?

Topics covered

#Elasticsearch#ElasticsearchStudyNotes#Database#MappingTypesExplained#Mapping#Types#Explained#Field#StudyNotes#SkillVeris