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


     

    elasticsearch 部分查询语句

    # 获取集群的节点列表:
    curl 'localhost:9200/_cat/nodes?v'
    
    # 列出所有索引:
    curl 'localhost:9200/_cat/indices?v'
    
    创建一个名为“customer”的索引,然后再查看所有的索引:
    curl -X PUT 'localhost:9200/customer?pretty'
    curl 'localhost:9200/_cat/indices?v'

    如果需要用户名和密码登录才可以访问,通过下面的方式指定用户名和密码
    # 获取集群的节点列表:
    curl --user username:password 'localhost:9200/_cat/nodes?v'
     

    参考链接: 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=<username>
                        password=<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了解还很少,中间可能有问题,还需要学习,就目前的了解程度,不保证上面的步骤完整,只是给大家一个大概的思路。

  • 相关阅读:
    Ant 警告:sun.misc.BASE64Decoder 是 Sun 的专用 API,可能会在未来版本中删除
    SerfJ REST
    SimpleDateFormat的线程安全问题与解决方案
    蔡勒(Zeller)公式:根据日期推算是星期几
    【转】详解 Spring 3.0 基于 Annotation 的依赖注入实现
    PostgreSQL JSON ARRAY 数据类型
    【转】Tomcat源代码阅读系列
    Spring 数据源
    IBatis-Spring 整合
    24 The Go image package go图片包:图片包的基本原理
  • 原文地址:https://www.cnblogs.com/resn/p/9082663.html
Copyright © 2020-2023  润新知