• elasticsearch-dump 迁移es数据 (elasticdump)


    elasticsearch部分查询语句

    复制代码

    # 获取集群的节点列表:
    curl ‘localhost:9200/_cat/nodesv’

    列出所有索引:

    curl ‘localhost:9200/_cat/indicesv’

    创建一个名为“customer”的索引,然后再查看所有的索引:
    curl -X PUT ‘localhost:9200/customerpretty’
    curl ‘localhost:9200/_cat/indicesv’

    复制代码

    参考链接:https://blog.csdn.net/pilihaotian/article/details/52452014

    github地址 :https://github.com/taskrabbit/elasticsearch-dump

    或者 :https://www.npmjs.com/package/elasticdump

    复制代码

    wget https://nodejs.org/dist/v8.11.2/node-v8.11.2-linux-x64.tar.xz

    tar xf node-v8.11.2-linux-x64.tar.xz

    mv node-v8.11.2-linux-x64 /usr/local

    ln -s /usr/local/node-v8.11.2-linux-x64/bin/npm /usr/local/bin/npm

    ln -s /usr/local/node-v8.11.2-linux-x64/bin/node /usr/local/bin/node

    npm init -f

    npm install elasticdump

    #因为我只用一次,所以这里没有安装到全局,需要到node_modules目录下才能找到 elasticdump , 我安装的位置如下:

    /usr/local/node-v8.11.2-linux-x64/node_modules/elasticdump/bin/elasticfump

    复制代码

    数据迁移:

    复制代码

    '#拷贝analyzer分词
    elasticdump
    –input=http://production.es.com:9200/my_index
    –output=http://staging.es.com:9200/my_index
    –type=analyzer
    '#拷贝映射
    elasticdump
    –input=http://production.es.com:9200/my_index
    –output=http://staging.es.com:9200/my_index
    –type=mapping
    '#拷贝数据
    elasticdump
    –input=http://production.es.com:9200/my_index
    –output=http://staging.es.com:9200/my_index
    –type=data

    复制代码

    复制代码

    # 注意 elasticdump 提供给了–httpAuthFile 参数来做认证
    –httpAuthFile When using http auth provide credentials in ini file in form
    `user=
    password=`

    只需要写一个ini文件 ,文件中写入用户名和密码就可以了

    这里其实还有另外一个好的方法

    在–input参数和–output参数的的url中添加账号密码

    例如

    elasticdump
    –input=http://prod-username:prod-passowrd@production.es.com:9200/my_index
    –output=http://stage-username:stage-password@staging.es.com:9200/my_index
    –type=data

    复制代码

    如果网络情况不好,或者没有网络还可以先备份到文件:

    复制代码

    # 备份索引数据到文件里:
    elasticdump
    –input=http://production.es.com:9200/my_index
    –output=/data/my_index_mapping.json
    –type=mapping
    elasticdump
    –input=http://production.es.com:9200/my_index
    –output=/data/my_index.json
    –type=data

    备份到标准输出,且进行压缩(这里有一个需要注意的地方,我查询索引信息有6.4G,用下面的方式备份后得到一个789M的压缩文件,这个压缩文件解压后有19G):

    elasticdump
    –input=http://production.es.com:9200/my_index
    –output=$
    | gzip > /data/my_index.json.gz

    把一个查询结果备份到文件中

    elasticdump
    –input=http://production.es.com:9200/my_index
    –output=query.json
    –searchBody ‘{“query”:{“term”:{“username”: “admin”}}}’

    复制代码

    elasticdump还是非常方便的,主要是可以指定查询条件,把查询结果进行备份。如果按照日期进行查询,那么就可以迁移指定之间段内的数据,

    恢复数据

    # 将备份文件的数据导入ES
    elasticdump
    –input=./data.json
    –output=http://es.com:9200

    其实对ES了解还很少,中间可能有问题,还需要学习,就目前的了解程度,不保证上面的步骤完整,只是给大家一个大概的思路。

    程度,不保证上面的步骤完整,只是给大家一个大概的思路。

  • 相关阅读:
    【hive基础】hive常见操作速查
    3.Linux传统性能检测工具——vmstat
    Cascade-MVSNet论文笔记
    私有化轻量级持续集成部署方案--01-环境配置(上)
    GB/T 10707 橡胶燃烧性能
    Cemotion情感分析
    【分享贴】VUCA环境下实现价值交付,PMO亟待转型
    NameNode 和 SecondaryNameNode 工作机制
    顺序栈的实现----数据结构
    Swift SwiftUI 隐藏键盘
  • 原文地址:https://blog.csdn.net/m0_67401417/article/details/126360031