chapter four

4 Mapping

 

This chapter covers

  • Filed data types
  • Implicit and explicit mapping
  • Core data types
  • Advanced data types
  • APIs to create/access the mappings

Data is like a rainbow—it comes in all sorts of “colors”. Business data comes in various shapes and forms, usually represented as textual information, dates, numbers, inner objects, booleans, geo-locations, IP addresses, and so on. In Elasticsearch, we model and index data as JSON documents, with each document consisting of a number of fields, and every field of a certain type of data. For example, a movie document consists of a title and synopsis represented as textual data, a release date as date, gross earnings as floating-point data, and so on.

In our earlier chapters, when we indexed sample documents, we did not bother about the data type of the fields. That’s because Elasticsearch derived these types implicitly by looking at the field and the type of information in it. Elasticsearch created a schema for us without us having to do any up front work unlike in a relational database. It is mandatory to have the table schema defined and developed in a database before proceeding to retrieve or persist the data.

4.1 Overview of mapping

4.1.1 Mapping definition

4.1.2 Indexing a document for the first time

4.2 Dynamic mapping

4.2.1 The deducing types mechanism

4.2.2 Limitations of dynamic mapping

4.3 Explicit mapping

4.3.1 Mapping using the indexing API

4.3.2 Updating schema using the mapping API

4.3.3 Modifying the existing fields is not allowed

4.3.4 Type coercion

4.4 Data types

4.4.1 Data type classifications

4.4.2 Developing mapping schemas

4.5 Core Data Types

4.5.1 The text data type

4.5.2 The keywords data types

4.5.3 The date data type

4.5.4 Numeric data types

4.5.5 The boolean data type

4.5.6 The range data type

4.5.7 The IP (ip) address data type

4.6 Advanced data types