mappings 就相当于 关系型数据库中的 表结构
例: GET t1
{
"t1" : {
"aliases" : { }, # 该索引是否有别名
"mappings" : { #mappings 信息
"doc" : { #索引类型 doc
"properties" : { #字段详细映射关系 在 properties中
"name" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
}
},
"settings" : { #关于索引 t1 的settings 设置
"index" : {
"creation_date" : "1553334893136", #索引创建时间
"number_of_shards" : "5", #主分片
"number_of_replicas" : "1", #副分片
"uuid" : "lHfujZBbRA2K7QDdsX4_wA",
"version" : {
"created" : "6050499"
},
"provided_name" : "t1"
}
}
}
}
ES 中的 映射 用来 定义一个文档及其包含的字段如何存储 和索引的过程。 例如,我们可以使用映射来定义:
每个索引都有一个映射类型 (在ES 6.0 版本之前 一个索引下有多个类型) ,它决定了文档将如何被索引
映射类型有:
_index、_type、_id和_source字段。text)、关键字(keyword)、日期(date)、整形(long)、双精度(double)、布尔(boolean)或ip。JSON的层次结构性质的类型,如对象或嵌套。geo_point、geo_shape或completion。为了不同的目的,以不同的方式索引相同的字段通常是有用的。例如,字符串字段可以作为全文搜索的文本字段进行索引,也可以作为排序或聚合的关键字字段进行索引。或者,可以使用标准分析器、英语分析器和法语分析器索引字符串字段。
这就是多字段的目的。大多数数据类型通过fields参数支持多字段。
在索引中定义太多的字段有可能导致映射爆炸!因为这可能会导致内存不足以及难以恢复的情况,为此。我们可以手动或动态的创建字段映射的数量:
PUT mapping_test1
{
"mappings": {
"test1":{
"properties":{
"name":{"type": "text"},
"age":{"type":"long"}
}
}
}
}
上例中,我们在创建索引PUT mapping_test1的过程中,为该索引定制化类型(设计表结构),添加一个映射类型test1;指定字段或者属性都在properties内完成
GET mapping_test1
通过GET来查看。
{
"mapping_test1" : {
"aliases" : { },
"mappings" : {
"test1" : {
"properties" : {
"age" : {
"type" : "long"
},
"name" : {
"type" : "text"
}
}
}
},
"settings" : {
"index" : {
"creation_date" : "1550469220778",
"number_of_shards" : "5",
"number_of_replicas" : "1",
"uuid" : "7I_m_ULRRXGzWcvhIZoxnQ",
"version" : {
"created" : "6050499"
},
"provided_name" : "mapping_test1"
}
}
}
}
原文:https://www.cnblogs.com/zhukaijian/p/12879702.html