es更新mapping是一个非常规的操作,下面是操作执行脚本:
from elasticsearch import Elasticsearch
from elasticsearch import helpers
esIp = "127.0.0.1"
esPort = "9200"
fromIndex = "old_index"
targetIndex = "new_index"
new_mapping = {"mappings": {"_doc": {"properties": {"id": {"type": "long"}, "title": {"type": "text", "analyzer": "ik_max_word", "search_analyzer": "ik_smart", "fields": {"keyword": {"type": "keyword", "ignore_above": 256}}}, "content": {"type": "text", "analyzer": "ik_max_word", "search_analyzer": "ik_smart", "fields": {"keyword": {"type": "keyword", "ignore_above": 256}}}}}}}
bulk_read = 1000
scroll = "5m"
# 连接elasticsearch
es = Elasticsearch([esIp], http_auth=("my_name", "my_pwd"), port=esPort)
# 创建新索引
es.indices.create(index=targetIndex, body=new_mapping)
helpers.reindex(client=es, source_index=fromIndex, target_index=targetIndex, target_client=es, query={"query": {"match_all": {}}}, chunk_size=bulk_read)
# 删除旧索引
es.indices.delete(fromIndex)
# 索引设置别名
es.indices.put_alias(index=targetIndex, name=fromIndex)
精选应用推荐
安全便捷的密码管理工具
安全加密
跨设备同步
一键填充
免费使用
云幻梦密码本 - 安全密码管理
云幻梦密码本是一款专业级密码管理工具,采用银行级加密技术保护您的所有密码和个人信息。支持跨设备同步、一键自动填充、安全密码生成和生物识别登录等功能,让您的数字生活更加安全便捷。
选择平台下载
资源搜索推荐
一站式资源搜索平台
资源搜索
多源聚合
免费使用
无广告
千搜123 | 资源搜索
智能搜索
多类资源
快速响应
安全访问
千搜123是一个强大的资源搜索网站,聚合了多种资源搜索引擎,提供文档、软件、影视、音乐、学习资料等多种资源的快速搜索服务。界面简洁无广告,搜索结果精准,是您寻找各类资源的得力助手。
- 聚合多个优质资源搜索引擎,一站式搜索
- 支持文档、软件、影视、学习资料等多种资源类型
- 界面简洁,无干扰广告,专注搜索体验
- 搜索结果快速准确,节省您的时间


