Elasticsearch 不支持现有字段映射更新。可以通过正确创建映射一个新的索引,然后将原索引上的数据复制到新的索引上,再将 alias 指向新 indices。然后再删除原索引。
-
将原索引 test 添加 alias
curl -X POST "http://192.168.1.101:9200/_aliases?pretty" -H 'Content-Type: application/json' -d' { "actions": [ { "add": { "index": "test_source", "alias": "test" } } ] } '
或
curl -X PUT "http://192.168.1.101:9200/test_source/_alias/test?pretty"
-
创建新索引 test_new
curl -X PUT "http://192.168.1.101:9200/test_new?pretty" curl -X POST "http://192.168.1.101:9200/test_new/_mapping?pretty" -H 'Content-Type: application/json' -d' { "properties": { "title": { "type": "text", "analyzer":"ik_max_word", "search_analyzer":"ik_smart" }, "content": { "type": "text", "analyzer":"ik_max_word", "search_analyzer":"ik_smart" }, "author": { "type": "keyword" }, "category": { "type": "keyword" } } } '
查看原索引 mapping
curl -X GET "http://192.168.1.101:9200/test_source/_mapping?pretty" { "test_source" : { "mappings" : { "properties" : { "author" : { "type" : "keyword" }, "category" : { "type" : "keyword" }, "content" : { "type" : "text" }, "title" : { "type" : "text" } } } } }
-
从原索引复制数据到新索引
注意: 不宜用于复制数据量过大的索引
curl -X POST "http://192.168.1.101:9200/_reindex?pretty" -H 'Content-Type: application/json' -d' { "source": { "index": "test_source" }, "dest": { "index": "test_new" } } '
-
修改别名
curl -X POST "http://192.168.1.101:9200/_aliases?pretty" -H 'Content-Type: application/json' -d' { "actions": [ { "remove" : { "index" : "test_source", "alias" : "test" } }, { "add": { "index": "test_new", "alias": "test" } } ] } '
-
删除旧索引 test_source
curl -X DELETE "http://192.168.1.101:9200/test_source?pretty"
网友评论