说明
不需要提前创建 索引(index)、映射(mapping),可直接向ES中插入文档数据, ES会根据 每个field的值,推断可能的数据类型,自动为其配置type等mapping信息
这就是动态映射(dynamic mapping)
测试
向一个不存在的索引 ceshi 添加数据,如下:
POST /ceshi/_doc
{
"name": "李雷",
"age": 20,
"length":1.82,
"is_boy":true,
"birthday":"2021-08-30"
}
查看映射
GET /ceshi/_mapping
结果如下:
{
"ceshi":{
"mappings":{
"properties":{
"age":{
"type":"long"
},
"birthday":{
"type":"date"
},
"is_boy":{
"type":"boolean"
},
"length":{
"type":"float"
},
"name":{
"type":"text",
"fields":{
"keyword":{
"type":"keyword",
"ignore_above":256
}
}
}
}
}
}
}
结论
true/false:推断类型为 bool
20:推断类型为 long
1.82:推断类型为 float
“2002-08-30”:推断类型为 date
“李雷” text:推断类型为
"name":{
"type":"text",
"fields":{
"keyword":{
"type":"keyword",
"ignore_above":256
}
}
}