liveBook · Manning

Data type

As explained in Elasticsearch in Action, Second Edition

A data type is a mapping specification that determines how a document field's values are represented, indexed, and queried in Elasticsearch.

A data type tells Elasticsearch how to represent, index, and search a document field. In a movie record, a title and synopsis are textual values, a release date is a date, and gross earnings can be a floating-point number. These choices become mapping rules: they describe the document shape and determine how each field is handled during indexing. section 4.0 section 4.1

Choosing the right type affects what a field can do. Text fields can use full-text rules, while structured values such as dates and numbers can participate in filtering, sorting, and aggregations. Elasticsearch stores different types in suitable retrieval structures, including inverted indexes for text and BKD trees for numeric fields, so accurate types support reliable search results. section 4.0 section 4.1.1

Elasticsearch groups its many data types into practical families:

  • Simple types represent common values: text, keyword, boolean, dates, whole numbers, floating-point numbers, and binary data. section 4.4
  • Complex types model composed JSON data: object, nested, flattened, and join. section 4.4
  • Specialized types support focused use cases, including geo_point and geo_shape for locations, ip addresses, and range values. section 4.4 section 12.1
Table 4.1 Common data types with examples (view table figure)

Type

Description

Examples

text

Represents textual information (such as string values); unstructured text

Movie title, blog post, book review, log message

integer, long, short, byte

Represents a number

Number of infectious cases, flights canceled, products sold, book’s rank

float, double

Represents a floating-point number

Student’s grade point average, moving average of sales, reviewer average ratings, temperature

boolean

Represents a binary choice: true or false

Is the movie a blockbuster? Are COVID cases on the rise? Has the student passed the exam?

keyword

Represents structured text: text that must not be broken down or analyzed

Error codes, email addresses, phone numbers, Social Security numbers

object

Represents a JSON object

(In JSON format) employee details, tweets, movie objects

nested

Represents an array of objects

Employee address, email routing data, a movie’s technical crew

Compare common field types with the business values they represent before designing a mapping. section 4.4

A mapping can be explicit or dynamic. With dynamic mapping, Elasticsearch derives a field type when it first sees a value: a movie title string becomes text, an ISO 8601 release-date string becomes date, and a numeric rating becomes float. This is useful for development and testing, but defining a schema first is preferable when the data model is known. section 4.2 section 4.8

Product fields chosen for search

An electrical-products index defines price and user_ratings as double values. Other attributes are text fields, and fields such as colour or energy_rating may use multiple types, including text and keyword, when both full-text and term-level queries are needed. Type selection follows the queries the application must support. section 11.1.1

Listing 11.1 Defining the products schema
PUT products
{
  "mappings": {
    "properties": {
      "brand": {
        "type": "text"
      },
      "colour": {
        "type": "text"
      },
      "energy_rating": {
        "type": "text"
      },
      ...
      "user_ratings": {
        "type": "double"
      },
      "price": {
        "type": "double"
      }
 
    }
  }
}

Inspect a mapping that creates an empty products index and assigns types before documents are indexed. section 11.1.1

Type coercion can reduce indexing failures when an incoming value differs from the mapped type. For example, a field mapped as an integer can accept the string "2" if Elasticsearch can parse it as the expected numeric value. Coercion is not a substitute for clean input: it works only when the value matches the target type after parsing. section 4.3.4

How Elasticsearch in Action, Second Edition covers it

How deep it goes
Explains mapping behavior, storage structures, type categories, dynamic inference, and coercion, while deferring a complete type catalog.
Examples
Uses movie fields, an electrical-products schema, geospatial fields, and a car age supplied as a string.
What it assumes
Introduces field schemas through familiar JSON values while relating them to programming-language and relational-database types.
What you can do after
Apply it via Elasticsearch mappings to select field types that support intended indexing and query behavior.
How it connects
Connects data types to mapping, dynamic mapping, type coercion, full-text queries, aggregations, sorting, and filtering.

Also explained in

Compare how 18 books explain data type →

Related concepts

This explainer was generated by Manning's knowledge graph from the text of Elasticsearch in Action, Second Edition. The section links point to the parts of the book it draws on.