Please note, this is a STATIC archive of website www.javatpoint.com from 19 Jul 2022, cach3.com does not collect or store any user information, there is no "phishing" involved.
Javatpoint Logo
Javatpoint Logo

Elasticsearch Mapping

Elasticsearch offers a mapping mechanism to its users. It allows the users to perform mapping on documents and their fields. A mapping is a process of indexing or storing the documents and fields in the database. It defines how the documents and their fields are stored and indexed.

We can define the datatypes for different types of fields, like - string, numbers, geo_point, etc. Therefore, to treat numeric fields as numbers, string fields as full-text or exact-value strings, and date fields as dates, Elasticsearch needs to know the datatype of each field. This information is stored in the mapping. Below is some important point to be noticed about mapping:

  • Mapping allows us to define the datatypes for the fields, e.g., string datatype for the name field.
  • It specifies the format of the fields provided in the document.
  • Mapping is also used to configure the metadata associated with the type.

The following example will show you a demo of simple mapping, in which we will create an index named books with mapping -

Copy code

Response

Screenshot

Elasticsearch Mapping

Datatype

Elasticsearch supports various datatypes for different fields. Let's discuss each datatype in brief:

Core datatype: These are the basic datatypes that are widely used. Some core datatypes are - short, integer, long, float, double, string, byte, Boolean, and date. These datatypes are supported by most of the systems.

Complex datatype: Complex datatypes are user-defined datatypes, which is the collection of core datatypes. The complex datatypes are - array, JSON objects (hierarchical in nature), and nested datatypes.

Geo datatype: Geo datatypes are the special type of datatype, which is used to store the geographical details like the location of a place. For example -

  • The geo_point helps to identify the longitude and latitude.
  • The geo_shape helps to define different geometric shapes like rectangles.

Specialized datatype: These datatypes are specialized datatype that holds the details which are unique such as IP address, token_count for counting the number of tokens in a string, and the auto-complete suggestions.

Mapping types

Every index has more than one type of mapping, which further divides the documents of the index into logical groups or chunks.

Mapping can be different from each other based on some factors such as Fields and Meta Fields.

Field or Properties: Fields are also be considered as properties. In elasticsearch, different mapping has various fields having different datatypes. In an index, fields with the same name but in different mapping types must have the same mapping.

Meta Fields: Meta fields make the information available about mapping as well as other objects associated with it, such as _index, _id, _source, and _type fields. They are responsible for customizing how the metadata associated with the document is treated.

Dynamic Mapping:

Elasticsearch provides a mechanism to create the mapping automatically. This user-friendly mechanism is referred to as dynamic mapping. It allows the users to post the data directly to any undefined mapping. Elasticsearch then automatically creates the mapping for it.

Static Mapping:

In most cases, we already know the kind of data that gets saved in the document. So, whenever we create an index, it becomes easy to define fields and their types. This mechanism is called as static mapping, which is created by the user at index creation time.

Mapping Parameters

Mapping parameters are the essential and fundamental factors that define the mapping. They also help to store the crux of the data - fields, and storage. Mapping parameters are responsible for how these details analyzed while being searched for. In Elasticsearch, following are the mapping parameters -

  • analyzer
  • boost
  • coerce
  • copy_to
  • doc_values
  • dynamic
  • enabled
  • fields
  • fielddata
  • format
  • geohash
  • geohash_prefix
  • geohash_precision
  • ignore_above
  • ignore_malformed
  • include_in_all
  • Index_options
  • lat_lon
  • norms
  • null_value
  • position_increment_gap
  • properties
  • search_analyzer
  • similarity
  • store
  • team_vector

Get mapping details for index

Following command is used to get mapping associated with an index -

Copy Code

Response

Screenshot

Elasticsearch Mapping

Removal of Mapping types

Elasticsearch 7.0.0 and higher versions do not support a _default_ mapping for indexes. However, an index created in Elasticsearch 6.x will continue to work as before. Types are deprecated in APIs in Elasticsearch 7.0 version.







Youtube For Videos Join Our Youtube Channel: Join Now

Feedback


Help Others, Please Share

facebook twitter pinterest

Learn Latest Tutorials


Preparation


Trending Technologies


B.Tech / MCA