映射管理
1 设置映射
PUT映射API用于将字段添加到已存在索引中或更改已存在字段的仅搜索设置。
PUT ttt/_mapping/ads
{
"properties": {
"esc": {
"type": "keyword"
}
}
}
note:向已存在的索引ttt添加新的类型ads,此类型中包含一个类型为keyword的字段。
多索引
PUT映射API可以使用单个请求应用到多个索引中。
PUT ttt,tts/mappings/sc
{
"properties": {
"log":{
"type":"keyword"
},
"kkk":{
"type":"text"
}
}
}
note:同时向ttt与tts两个索引中更新类型sc,sc中包含有两个字段,一个是类型为keyword的log,另一个是类型为text的kkk。
注意,被指定的多个索引需要遵守多索引名称以及通配符格式。
更新字段匹配
通常情况下,映射中已经存在的字段不会被更新。
这里有一些意外情况:
- 新properties被添加进Object数据类型字段中
- 新multi-fields被添加进已存在字段中
- ignore_above参数被更改
PUT my_index/_mapping/_doc
{
"properties": {
"name": {
"properties": {
"last": {
"type": "keyword"
}
}
}
}
}
note:向已经存在的索引my_index的类型_doc的已存在Object数据类型字段name添加新字段,keyword类型的last。
PUT my_index/_mapping/_doc
{
"properties": {
"kkk": {
"type": "text",
"fields": {
"ggg": { "type": "keyword"}
}
}
}
}
note:为字段kkk设置多字段,kkk.ggg类型为keyword。
PUT my_index/_mapping/_doc
{
"properties": {
"user_id": {
"type": "keyword",
"ignore_above": 100
}
}
}
note:将user_id字段的参数ignore_above设置为100。