ES间的导数脚本

一、同节点


from elasticsearch import Elasticsearch

# 连接到源Elasticsearch集群
source_es = Elasticsearch('http://127.0.0.1:9201')
 
# 连接到目标Elasticsearch集群
target_es = Elasticsearch('http://127.0.0.1:9200')
 
# 定义源索引和目标索引
source_index = 't1'
target_index = 't2'
 
# 使用_reindex API从源索引导入数据到目标索引
reindex_body = {
    "source": {
        "index": source_index 
    },
    "dest": {
        "index":target_index
    }
}
 
response = target_es.reindex(body=reindex_body)
 
# 打印结果
print(response)

二、跨节点


from elasticsearch import Elasticsearch
from elasticsearch.helpers import scan, bulk
source_index = 't1'
target_index = 't1'
# 连接到源Elasticsearch集群
source_client = Elasticsearch('http://127.0.0.1:9201')
# 连接到目标Elasticsearch集群
target_client = Elasticsearch('http://127.0.0.1:9200')
def scan_index(client,index):
    scan_results = scan(client, query={"query": {"match_all": {}}}, index=index)
    for result in scan_results:
        yield result
# 执行批量索引操作
def bulk_index_documents(client,index,documents):
    actions = []
    for document in documents:
        action = {
            "_op_type": "index",
            "_index": target_index,
            "_id": document["_id"],
            "_source": document["_source"]
        }
        actions.append(action)
    bulk(client, actions)
def main():
    
    documents = scan_index(source_client,source_index)
    # 批量索引到目标索引
    bulk_index_documents(target_client,target_index,documents)
    print('ok')
main()

相关推荐

  1. ES导数脚本

    2024-03-25 04:18:02       18 阅读
  2. 脚本批量导入导出es表结构

    2024-03-25 04:18:02       38 阅读
  3. ES实战--文档关系

    2024-03-25 04:18:02       43 阅读
  4. ES6模块化导入导出方式

    2024-03-25 04:18:02       38 阅读
  5. maya 导入导出anim脚本

    2024-03-25 04:18:02       18 阅读
  6. ES6导出mapping结构转为ES8结构

    2024-03-25 04:18:02       12 阅读
  7. ES8导出mapping批量修改索引名

    2024-03-25 04:18:02       12 阅读

最近更新

  1. TCP协议是安全的吗?

    2024-03-25 04:18:02       18 阅读
  2. 阿里云服务器执行yum,一直下载docker-ce-stable失败

    2024-03-25 04:18:02       19 阅读
  3. 【Python教程】压缩PDF文件大小

    2024-03-25 04:18:02       19 阅读
  4. 通过文章id递归查询所有评论(xml)

    2024-03-25 04:18:02       20 阅读

热门阅读

  1. clickhouse介绍

    2024-03-25 04:18:02       20 阅读
  2. 如何借助API提升产品设计的用户体验

    2024-03-25 04:18:02       18 阅读
  3. 数列特征

    2024-03-25 04:18:02       19 阅读
  4. MongoDB聚合运算符:$integral

    2024-03-25 04:18:02       15 阅读
  5. 简单杨氏矩阵

    2024-03-25 04:18:02       18 阅读
  6. vue3 + Element + nodejs 大文件上传、断点续传

    2024-03-25 04:18:02       21 阅读
  7. web渗透测试漏洞流程:红队攻防流程详细大纲

    2024-03-25 04:18:02       18 阅读
  8. linux telnet 用来判断网络是否通

    2024-03-25 04:18:02       21 阅读