环境: 阿里云ElasticSearch 6.7
需求: 给指定索引增加字段
- 创建一个索引
PUT /indexName
{
"settings": {
"number_of_shards": 2,
"number_of_replicas": 1
},
"mappings": {
"_doc": {
"properties": {
"id": {
"type": "long"
},
"name": {
"type": "text"
},
"picture_url": {
"type": "keyword"
}
}
}
}
}
查看创建好的索引mapping,显示如下:
{
"hello" : {
"mappings" : {
"_doc" : {
"properties" : {
"id" : {
"type" : "long"
},
"name" : {
"type" : "text"
},
"picture_url" : {
"type" : "keyword"
}
}
}
}
}
}
- 增加新的字段
PUT /hello/_doc/_mapping
{
"properties": {
"extendInfo": {
"type": "text"
},
"stock": {
"type": "integer"
}
}
}
再次查看该索引的mapping,发现mapping发生了改变,字段增加上去了。
{
"hello" : {
"mappings" : {
"_doc" : {
"properties" : {
"extendInfo" : {
"type" : "text"
},
"id" : {
"type" : "long"
},
"name" : {
"type" : "text"
},
"picture_url" : {
"type" : "keyword"
},
"stock" : {
"type" : "integer"
}
}
}
}
}
}
- 如果是嵌套节点下面新增字段
PUT hello/_doc/_mapping
{
"properties": {
"channelTradeNo": {
"type": "keyword",
"norms": false,
"doc_values": false
},
"orderDetails": {
"type": "nested",
"properties": {
"rightsStatus": {
"type": "keyword",
"norms": false,
"doc_values": false
},
"rightsCurrTime": {
"type": "keyword",
"norms": false,
"doc_values": false
},
"rightsEndTime": {
"type": "keyword",
"norms": false,
"doc_values": false
}
}
}
}
}
结束语:分享是一种乐趣,你知道的越多,你知道的越少。