Elasticsearch修改字段类型 (_reindex)
2024-08-30 14:37:42
1.设置索引t2为想要的数据类型
2.将t1 reindex到t2
3.数据reindex完成删除t1
4.设置索引t1为想要的数据类型
5.将t2 reindex到t1
如果 _reindex 超时 返回504等
通过语句可以看到任务还在进行, 数据还在迁移中
GET _tasks?actions=*reindex&detailed
PUT t1
{
"settings": {
"index": {
"number_of_shards": "2",
"analysis": {
"analyzer": {
"ik_custom_analyzer": {
"filter": [
"lowercase"
],
"type": "custom",
"tokenizer": "ik_max_word"
}
}
},
"number_of_replicas": "1"
}
},
"mappings": {
"doc": {
"properties": {
"abs_path": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"comp_id": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"id": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"id_path": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"index_update_time": {
"type": "long"
},
"name": {
"type": "text",
"analyzer": "ik_custom_analyzer"
},
"parent_id": {
"type": "text",
"fields": {
"keyword": {
"type": "keyword",
"ignore_above": 256
}
}
},
"star": {
"type": "long"
},
"time": {
"type": "long"
},
"weight": {
"type": "long"
}
}
}
}
}
PUT /t2
{
"settings": {
"number_of_shards": 2,
"number_of_replicas": 1,
"analysis": {
"analyzer": {
"simplechar_index_analyzer": {
"type": "custom",
"tokenizer": "simplechar_index"
},
"simplechar_search_analyzer": {
"type": "custom",
"tokenizer": "simplechar_search"
},
"pinyin_index_analyzer": {
"type": "custom",
"tokenizer": "pinyin_index"
},
"pinyin_search_analyzer": {
"type": "custom",
"tokenizer": "pinyin_search"
}
},
"tokenizer": {
"simplechar_index": {
"type": "simplechar_and_pinyin",
"simple_char": true,
"prefix_en": true,
"prefix_num": true
},
"simplechar_search": {
"type": "simplechar_and_pinyin",
"simple_char": true,
"prefix_num": true,
"prefix_en": true
},
"pinyin_index": {
"type": "simplechar_and_pinyin",
"simple_char": true,
"han_to_pinyin": true,
"keep_first": true,
"keep_fuzzy": true,
"simple_num": true
},
"pinyin_search": {
"type": "simplechar_and_pinyin",
"simple_char": true,
"en_to_pinyin": true,
"simple_num": true
}
}
}
},
"mappings": {
"doc": {
"properties": {
"name": {
"type": "text",
"analyzer": "simplechar_index_analyzer",
"search_analyzer": "simplechar_search_analyzer",
"similarity": "boolean",
"fielddata": true,
"fields": {
"pinyin": {
"type": "text",
"similarity": "boolean",
"analyzer": "pinyin_index_analyzer",
"search_analyzer": "pinyin_search_analyzer",
"fielddata": true
}
}
}
}
}
}
}
PUT t1/doc/3
{
"id": "3",
"name": "第七层",
"star": 0,
"parent_id": "134111385604698112",
"comp_id": "500000151",
"abs_path": "啤啤第三个公司/这个是子部门1/这个是部门下的部门/再加/第五层/第六层/第七层",
"id_path": "131773053453164544,131775211384823808,131775319170052096,132666474766233600,134111338699763712,134111385604698112,134112080391122944",
"weight": "2",
"index_update_time": 1547469387,
"time": 1547469386994201600
}
GET t1/doc/_search
{
"size": 20,
"query": {
"match_all": {}
}
}
POST _reindex
{
"source": {
"index": "t1"
},
"dest": {
"index": "t2",
"version_type": "external"
},
"script": {
"source":"def w = ctx._source.remove('weight');ctx._source.weight=w;",
"lang": "painless"
}
}
GET t1/_mapping
GET t2/_mapping
GET t2/doc/_search
{
"size": 20,
"query": {
"match_all": {}
}
}
最新文章
- javascript,从库到框架再到平台
- sql 知识点系统汇总
- vue.js2.0的独立构建和运行时构建
- 3d加速的一些问题
- Linux下删除空文件,删除指定大小的文件
- ASP.NET MVC路由配置(转载自http://www.cnblogs.com/zeusro/p/RouteConfig.html )
- 字符串复制strncpy
- Codeforces Round #182 (Div. 1)题解【ABCD】
- Telegram
- 如何调用super
- $watch How the $apply Runs a $digest
- jQuery网页元素拖拽插件
- 关于size_t与size_type
- SDUT 1646 Complicated Expressions
- Android 国际化图片资源文件
- 分享,iOS国家手机区号代码.plist
- [UWP]如何使用代码创建DataTemplate(或者ControlTemplate)
- $Django 路飞之小知识回顾,Vue之样式element-ui,Vue绑定图片--mounted页面挂载--路由携带参数
- 基于MSMQ绑定的WCF服务实现总结
- 基于TLS证书手动部署kubernetes集群(上)