Bootstrap

Elasticsearch dynamic mapping

Elasticsearch dynamic mapping,文字内容来自 B 站中华石杉 Elasticsearch 高手进阶课程,英文内容来自官方文档。

核心的数据类型

  • string

  • byte,short,integer,long

  • float,double

  • boolean

  • date

Dynamic mapping

The automatic detection and addition of new fields is called dynamic mapping.

Date detection

PUT data/_doc/2
{
  "create_date": "2015/09/02"
}

GET data/_mapping

PUT date_detection_false
{
  "mappings": {
    "date_detection": false
  }
}

PUT date_detection_false/_doc/1
{
  "create": "2015/09/02"
}

GET date_detection_false/_mapping

DELETE date_custom

PUT date_custom
{
  "mappings": {
    "dynamic_date_formats": ["MM/dd/yyyy"]
  }
}

PUT date_custom/_doc/1
{
  "create_date": "09/25/2015"
}

Numeric detection

PUT numeric_detection
{
  "mappings": {
    "numeric_detection": true
  }
}

PUT numeric_detection/_doc/1
{
  "my_float": "1.0",    // float
  "my_integer": "1"     // long
}

GET numeric_detection/_mapping
Explicit mapping

Explicit mapping allows you to precisely choose how to define the mapping definition, such as :

  • which string fields should be treated as full text fields

  • which fields contain numbers, dates, or geolocations

  • The format of date values

  • Custom rules to control the mapping for dynamically added fields.

Mapping explosion

Defining too many fields in an index can lead to a mapping explosion, which can cause out of memory errors and difficult situations to recover from.

Use the mapping limit settings to limit the number of field mappings (created manually or dynamically) and prevent documents from causing a mapping explosion.

查看 mapping

GET /index/_mapping/type