
类似数据库中的表结构定义,主要作用如下:
{
"index" : {
"mappings" : {
"properties" : {
"JSON 数据" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"公众号" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
}
}
}
类似 MySQL,Mapping中的字段类型一旦设定后,禁止直接修改,原因如下:
允许新增字段 通过dynamic参数来控制字段的新增

将该字段的值复制到目标字段,实现类似 _all 的作用,不会出现在 _source 中,只用来搜索


控制当前字段是否索引,默认为true,即记录索引, false 不记录, 即不可搜索
控制倒排索弓引|记录的内容,有如下4种配置
text 类型默认配置为positions,其他默认为docs。记录内容越多,占用空间越大。
当字段遇到null值时的处理策略,默认为null,即空值,此时es会忽略该值。可以通过设定该值设定字段的默认值。



ES可以自动识别文档字段类型,从而降低用户使用成本,如下所示
PUT /test_index/doc/1
{
"username": "java",
"age": "18"
}
GET /test_index/_mapping{
"test_index" : {
"mappings" : {
"properties" : {
"age" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"username" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
}
}
}ES是依靠JSON文档的字段类型来实现自动识别字段类型,支持的类型如下:

PUT /test_index/doc/1
{"username":" alfred",
"age":14,
"birth":"1988-10-10",
"married":false,
"year":18,
"tags":["boy","fashion"],
"money":100.1
}
GET /test_index/_mapping{
"test_index" : {
"mappings" : {
"properties" : {
"age" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"birth" : {
"type" : "date"
},
"married" : {
"type" : "boolean"
},
"money" : {
"type" : "float"
},
"tags" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"username" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"year" : {
"type" : "long"
}
}
}
}
}默认是[ “strict_date_optional_time”,“yyyy/MM/dd HH:mm:ss Z||yyyy/MM/dd Z”]
strict_date_optional_time 是 ISO datetime 的格式,完整格式类似下面:date_detection 可关闭日期自动识别的机制允许根据es自动识别的数据类型、字段名等来动态设定字段类型,可以实现如下效果:

匹配规则一般有如下几个参数:
索引模板,英文为Index Template,主要用于在新建索引时自动应用预先设定的配置,简化索索引创建的操作步骤
_template ,如下所示:

获取与删除

参考