Elasticsearch 對映管理(一)——PUT
阿新 • • 發佈:2018-11-16
對映管理
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。