Elasticsearch 参考指南(Put Mapping)
文章目录
Put Mapping
PUT mapping API允许你向现有索引添加字段,或者仅更改现有字段的搜索设置。
PUT twitter
{}
PUT twitter/_mapping
{
"properties": {
"email": {
"type": "keyword"
}
}
}
- 创建一个名为
twitter的索引,不需要任何映射。 - 使用
PUT mappingAPI添加一个名为email的新字段。
有关如何定义映射的更多信息可以在映射部分中找到。
在7.0.0之前,映射定义用于包含类型名称,虽然现在不赞成在请求中指定类型,但是如果设置了请求参数include_type_name,仍然可以提供类型,有关详细信息,请参见删除映射类型。
多索引
PUT mapping API可以应用于单个请求的多个索引,例如,我们可以同时更新twitter-1和twitter-2的映射:
# Create the two indices
PUT twitter-1
PUT twitter-2
# Update both mappings
PUT /twitter-1,twitter-2/_mapping
{
"properties": {
"user_name": {
"type": "text"
}
}
}
- 注意,指定的索引(
twitter-1,twitter-2)遵循多索引名称和通配符格式。
更新字段映射
通常,无法更新现有字段的映射,这条规则有一些例外,例如:
- 可以向对象字段添加新
properties。 - 可以向现有字段添加新的多字段。
- 可以更新
ignore_above参数。
示例:
PUT my_index
{
"mappings": {
"properties": {
"name": {
"properties": {
"first": {
"type": "text"
}
}
},
"user_id": {
"type": "keyword"
}
}
}
}
PUT my_index/_mapping
{
"properties": {
"name": {
"properties": {
"last": {
"type": "text"
}
}
},
"user_id": {
"type": "keyword",
"ignore_above": 100
}
}
}
- 创建一个索引,其中
name对象字段下有first字段,user_id字段。 - 在
name对象字段下添加last字段。 - 从默认值
0更新ignore_above设置。
每个映射参数指定是否可以在现有字段上更新其设置。
评论
登录后参与技术讨论,分享你的经验与见解。
登录 / 注册暂无评论