Elasticsearch Mapping 详解
一、什么是 Mapping
ES 中的 Mapping 有点类似于关系型数据库中表结构的概念。在 MySQL 中,表结构包含了字段名称、字段类型以及索引信息等。在 Mapping 里也包含了一些属性,比如字段名称、类型、字段使用的分词器、是否评分、是否创建索引等,并且在 ES 中一个字段可以有多个类型。
PUT /my_index
{
"mappings": {
"properties": {
"title": { "type": "text", "analyzer": "ik_smart" },
"author": { "type": "keyword" },
"content": { "type": "text" },
"publish_date": { "type": "date", "format": "yyyy-MM-dd" },
"price": { "type": "double" },
"tags": { "type": "keyword" }
}
}
}
二、如何查看 Index 的 Mapping
2.1 查看完整 Mapping
GET /my_index/_mapping
2.2 查看指定字段
GET /my_index/_mapping/field/title
多个字段用逗号分隔:
GET /my_index/_mapping/field/title,content,author
2.3 批量查看多个索引
GET /logs-2024-*/_mapping
GET /my_index,my_other_index/_mapping
GET /_all/_mapping
