> For the complete documentation index, see [llms.txt](https://xiaoxiami.gitbook.io/elasticsearch/llms.txt). Markdown versions of documentation pages are available by appending `.md` to page URLs; this page is available as [Markdown](https://xiaoxiami.gitbook.io/elasticsearch/ji-chu/mapping/324dynamic-mappingff08-dong-tai-ying-she-ff09.md).

# 3.2.4.Dynamic Mapping（动态映射）

**Elasticsearch**最重要的功能之一就是让你尽可能快地开始探索数据。要索引文档，你不用立即创建**index**（索引），定义相关的

**mapping type**（映射类型）和定义相关的**fields**（字段）— 你可以只索引**document**（文档）、**index**（索引）、**type**（类型）和

**fields**（字段），这些操作都将自动生效。

```
PUT data/counters/1  # 1
{ "count": 5 }
```

| 1 | 创建名为**data**的索引，其中包含名为**counters**的**mappingtype**（映射类型），以及名为**count**的**long**数据类型。 |
| - | ------------------------------------------------------------------------------------ |

自动的检测和添加新的类型以及字段的过程，称之为动态映射。你可以根据需要定制动态映射的规则 :

[\_default\_ mapping](https://www.elastic.co/guide/en/elasticsearch/reference/5.3/default-mapping.html)（**\_default\_** 映射）

配置一个基本映射，作用于新的映射类型。

[Dynamic field mappings](https://www.elastic.co/guide/en/elasticsearch/reference/5.3/dynamic-field-mapping.html)（动态字段映射）

控制动态字段发现的规则。

[Dynamic templates](https://www.elastic.co/guide/en/elasticsearch/reference/5.3/dynamic-templates.html)（动态模板）

利用自定义规则来配置动态添加的字段的映射。

> Tips :
>
> 无论是自动还是显式的创建索引，[Index templates](https://www.elastic.co/guide/en/elasticsearch/reference/5.3/indices-templates.html)（索引模板）都允许你为一个新的索引配置**mappings**，**settings**和**aliases**（别名）。

## Disabling automatic type creation（禁用自动类型创建） <a href="#dynamicmapping-dong-tai-ying-she-disablingautomatictypecreation-jin-yong-zi-dong-lei-xing-chuang-jia" id="dynamicmapping-dong-tai-ying-she-disablingautomatictypecreation-jin-yong-zi-dong-lei-xing-chuang-jia"></a>

每个索引都可以通过将 **indexsetting**（索引设置）中的**index.mapper.dynamic**属性设置为**false**，来禁用**Automatic type creation**（自动创建类型）-（根据数据类型自动创建**mapping**）:

```
curl -XPUT 'localhost:9200/_template/template_all?pretty' -H 'Content-Type: application/json' -d'
{
  "index.mapper.dynamic":false   # 1
}
```

| 1 | 禁用名为 “**data**” 的索引的自动创建类型（根据数据类型自动创建**mapping**） |
| - | ------------------------------------------------- |

通过对索引模板的设置，可以禁用所有索引的自动创建类型（根据数据类型自动创建mapping)）:

```
curl -XPUT 'localhost:9200/_template/template_all?pretty' -H 'Content-Type: application/json' -d'
{
  "template": "*",
  "order":0,
  "settings": {
    "index.mapper.dynamic": false # 1
  }
}
'
```

| 1 | 禁用所有索引的自动创建类型(根据数据类型自动创建mapping) |
| - | -------------------------------- |

无论该属性如何设置，在 [创建索引](https://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-create-index.html) 或使用 [PUT mapping ](https://www.elastic.co/guide/en/elasticsearch/reference/5.2/indices-put-mapping.html)**API**时，我们仍然可以显式的添加**types**（类型）。


---

# Agent Instructions
This documentation is published with GitBook. GitBook is the documentation platform designed so that both humans and AI agents can read, navigate, and reason over technical content effectively. Learn more at gitbook.com.

## Querying This Documentation
If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter, and the optional `goal` query parameter:

```
GET https://xiaoxiami.gitbook.io/elasticsearch/ji-chu/mapping/324dynamic-mappingff08-dong-tai-ying-she-ff09.md?ask=<question>&goal=<endgoal>
```

`ask` is the immediate question: it should be specific, self-contained, and written in natural language.
`goal` is optional and describes the broader end goal you are ultimately trying to accomplish on behalf of the user. GitBook uses it to tailor the answer towards what is most useful for that goal.

The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
