PUT mapping
API容许你向现有索引添加字段,或者仅更改现有字段的搜索设置。segmentfault
PUT twitter {} PUT twitter/_mapping { "properties": { "email": { "type": "keyword" } } }
twitter
的索引,不须要任何映射。PUT mapping
API添加一个名为email
的新字段。有关如何定义映射的更多信息能够在映射部分中找到。app
在7.0.0以前,映射定义用于包含类型名称,虽然如今不同意在请求中指定类型,可是若是设置了请求参数
include_type_name
,仍然能够提供类型,有关详细信息,请参见
删除映射类型。
PUT mapping
API能够应用于单个请求的多个索引,例如,咱们能够同时更新twitter-1
和twitter-2
的映射:code
# 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
设置。每一个映射参数指定是否能够在现有字段上更新其设置。get