ElasticSearch修改索引类型

编程

以官方数据索引为例子 /shakespeare

1.获取原来的索引结构

GET /shakespeare

执行结果:

{

"shakespeare" : {

"aliases" : {},

"mappings" : {

"properties" : {

"line_id" : {

"type" : "long"

},

"line_number" : {

"type" : "text",

"fields" : {

"keyword" : {

"type" : "keyword",

"ignore_above" : 256

}

}

},

"play_name" : {

"type" : "text",

"fields" : {

"keyword" : {

"type" : "keyword",

"ignore_above" : 256

}

}

},

"speaker" : {

"type" : "text",

"fields" : {

"keyword" : {

"type" : "keyword",

"ignore_above" : 256

}

}

},

"speech_number" : {

"type": "text",

"fields": {

"keyword": {

"type": "keyword",

"ignore_above": 256

}

},

"text_entry" : {

"type" : "text",

"fields" : {

"keyword" : {

"type" : "keyword",

"ignore_above" : 256

}

}

},

"type" : {

"type" : "text",

"fields" : {

"keyword" : {

"type" : "keyword",

"ignore_above" : 256

}

}

}

}

},

"settings" : {

"index" : {

"creation_date" : "1591865027378",

"number_of_shards" : "1",

"number_of_replicas" : "1",

"uuid" : "5dtedNT6SyC_AG0ZhQwk5Q",

"version" : {

"created" : "7040299"

},

"provided_name" : "shakespeare2"

}

}

}

}

2.创建新的索引

PUT /shakespeare2

{

"mappings": {

"properties": {

"line_id": {

"type": "long"

},

"line_number": {

"type": "text",

"fields": {

"keyword": {

"type": "keyword",

"ignore_above": 256

}

}

},

"play_name": {

"type": "text",

"fields": {

"keyword": {

"type": "keyword",

"ignore_above": 256

}

}

},

"speaker": {

"type": "text",

"fields": {

"keyword": {

"type": "keyword",

"ignore_above": 256

}

}

},

"speech_number": {

"type": "long" //这里修改为 long 类型

},

"text_entry": {

"type": "text",

"fields": {

"keyword": {

"type": "keyword",

"ignore_above": 256

}

}

},

"type": {

"type": "text",

"fields": {

"keyword": {

"type": "keyword",

"ignore_above": 256

}

}

}

}

}

}

同步数据

POST _reindex                   

{

"source": {

"index": "shakespeare"

},

"dest": {

"index": "shakespeare2"

}

}

删除老索引

DELETE shakespeare

别名设置

POST /_aliases

{

"actions": [

{

"add": {

"index": "shakespeare2",

"alias": "shakespeare"

}

}

]

}

以上是 ElasticSearch修改索引类型 的全部内容, 来源链接: utcz.com/z/517320.html

回到顶部