暂时没有找到直接 导出到 mysql 数据库的工具 或者项目

目前实现思路: 使用 elasticdump  工具 实现 从 es 数据 导出到 json 文件 ,然后 使用 脚本程序 操作 改 json 文件 实现 导入到MySQL 数据

具体内容如下:

安装elasticdump
 1 npm install elasticdump -g elasticdump 全局安装
 2 从 github 下载 对应的版本  比如 2.4.*

具体参考 https://www.npmjs.com/package/elasticdump
  github 地址 https://github.com/taskrabbit/elasticsearch-dump

安装完成后,就可以使用了,下面举一个例子(将索引a中的数据导入到索引b中):
elasticdump  用法详解

./elasticdump --input=http://127.0.0.1:9200/domain6 --output=query.json --debug=true --limit=1 --offset=0 --searchBody='{"query":{"range":{"id":{"lte":"100"}}}}' --sourceOnly=true

// 获取 所需的字段值
./elasticdump --input=http://127.0.0.1:9200/domain6 --output=query2.json --limit=100 --offset=0 --searchBody='{"query":{"range":{"id":{"lte":"80"}}},"_source":["id","cname"]}' --sourceOnly=true

//问题 类似 es  size 的功能 暂时还没找到方案  
./elasticdump --input=http://127.0.0.1:9200/domain6 --output=query3.json --limit=100 --offset=0 --searchBody='{"query":{"range":{"id":{"lte":"80"}}},"_source":["id","cname"]}' --sourceOnly=true

--input 原数据源
--output 导出数据地址
--limit (不是导出总条数 和 es 有区别) 每次执行 导入的数据条数
--offset  相当于 es 里面 的from
--searchBody  查询语句
--sourceOnly  导出数据格式 默认会把 _type _id _source _index 都导出 默认 false

elasticdump --input=http://localhost:9200/a --output=http://localhost:9200/b --type=data
elasticdump --input=http://localhost:9200/domain_v12 --output=D:/ziliao/elasticsearch-2.3.3/dd --type=data
elasticdump --input=http://localhost:9200/domain_v12 --limit=10 --output=D:/ziliao/elasticsearch-2.3.3/dd4.json  --type=data

执行数据迁移
导出Mapping信息
elasticdump --ignore-errors=true  --scrollTime=120m  --bulk=true --input=http://10.10.20.164:9200/xmonitor-2015.04.29   --output=http://192.168.100.72:9200/xmonitor-prd-2015.04.29  --type=mapping
导出数据
elasticdump --ignore-errors=true  --scrollTime=120m  --bulk=true --input=http://10.10.20.164:9200/xmonitor-2015.04.28   --output=/usr/local/esdump/node-v0.12.2-linux-x64/data/xmonitor-prd-2015.04.28.json --type=data
导出数据到本地集群
elasticdump --ignore-errors=true  --scrollTime=120m  --bulk=true --input=http://10.10.20.164:9200/xmonitor-2015.04.29   --output=http://192.168.100.72:9200/xmonitor-prd-2015.04.29 --type=data

var defaults = {
  limit:              10,
  offset:             0,
  debug:              false,
  type:               'data',
  delete:             false,
  maxSockets:         null,
  input:              null,
  'input-index':      null,
  output:             null,
  'output-index':     null,
  inputTransport:     null,
  outputTransport:    null,
  searchBody:         null,
  sourceOnly:         false,
  jsonLines:          false,
  format:             '',
  'ignore-errors':    false,
  scrollTime:         '10m',
  timeout:            null,
  toLog:              null,
  quiet:              false,
  awsAccessKeyId:     null,
  awsSecretAccessKey: null,
};
npm install elasticdump2.1.0 -g
elasticdump

npm install elasticdump@2.*

从json文件  导入 MySQL
<?php 
$json_data = file_get_contents('D:/ziliao/node_modules/elasticdump/bin/query1223.json');(json 文件 所有路径)
$len = strlen($json_data);
$begin = 0;
$end = 0;
$data = [];
for ($i=0; $i < $len; $i++) { 
  if($json_data[$i]=="}")
  { 
    $end = $i;
    $lens = $end-$begin+1;
    $data[] = json_decode(substr($json_data,$begin ,$lens),true);
    $begin = $end+1;
  }
}
// print_r($data);
// 链接 MySQL 数据库 配置 
$con = mysql_connect("localhost","root","");
if (!$con)
{
  die('Could not connect: ' . mysql_error());
}
mysql_select_db("adbug", $con);
foreach ($data as $key => $value) {
  $sql = "INSERT INTO test2 (name) VALUES ('".$value['host']."')";
  mysql_query($sql);
}
mysql_close($con);
?> 

es 数据 导出 到 MySQL的更多相关文章

  1. MSSQL数据导出到MYSQL

    MSSQL数据导出到MYSQL 花了一天时间把MSSQL里的数据导出到MYSQL, 好麻烦,二个数据库都是阿里云买的云服务器. 先上阿里云控制面板,备份下MSSQL数据库,下载备份下来,在本地电脑上还 ...

  2. 使用JDBC+POI把Excel中的数据导出到MySQL

    POI是Apache的一套读MS文档的API,用它还是可以比较方便的读取Office文档的.目前支持Word,Excel,PowerPoint生成的文档,还有Visio和Publisher的. htt ...

  3. 从hive将数据导出到mysql(转)

    从hive将数据导出到mysql http://abloz.com 2012.7.20 author:周海汉 在上一篇文章<用sqoop进行mysql和hdfs系统间的数据互导>中,提到s ...

  4. Sqoop2 将hdfs中的数据导出到MySQL

    1.进入sqoop2终端: [root@master /]# sqoop2 2.为客户端配置服务器: sqoop:000> set server --host master --port 120 ...

  5. 用java代码调用shell脚本执行sqoop将hive表中数据导出到mysql

    1:创建shell脚本 touch sqoop_options.sh chmod 777 sqoop_options.sh 编辑文件  特地将执行map的个数设置为变量  测试 可以java代码传参数 ...

  6. 使用 sqoop 将 hive 数据导出到 mysql (export)

    使用sqoop将hive中的数据传到mysql中 1.新建hive表 hive> create external table sqoop_test(id int,name string,age ...

  7. 《sqoop实现hdfs中的数据导出至mysql数据库》

    报错Access denied for user 'root'@'localhost' (using password: YES)  参考一  参考二 登陆mysql时,root密码的修改 参考帖子h ...

  8. (MySQL里的数据)通过Sqoop Import Hive 里 和 通过Sqoop Export Hive 里的数据到(MySQL)

    Sqoop 可以与Hive系统结合,实现数据的导入和导出,用户需要在 sqoop-env.sh 中添加HIVE_HOME的环境变量. 具体,见我的如下博客: hadoop2.6.0(单节点)下Sqoo ...

  9. (MySQL里的数据)通过Sqoop Import HBase 里 和 通过Sqoop Export HBase 里的数据到(MySQL)

    Sqoop 可以与HBase系统结合,实现数据的导入和导出,用户需要在 sqoop-env.sh 中添加HBASE_HOME的环境变量. 具体,见我的如下博客: hadoop2.6.0(单节点)下Sq ...

随机推荐

  1. AWS文档与用户指南

    AWS Command Line Interface http://docs.amazonaws.cn/cli/latest/userguide/cli-chap-welcome.html VM Im ...

  2. WebKit学习资源

    1.http://blog.csdn.net/dlmu2001/article/category/741748    红心地瓜 2.http://blog.csdn.net/cnnzp/article ...

  3. jw player学习笔记三---发布到其它网站

    一.通过官网发布向导 登陆 http://www.longtailvideo.com,注册一个账号,进入你的用户管理中心,如下图 然后按提示,一步步操作,就会得到js代码了. 二.自己服务器发布 &l ...

  4. C# windows application Hello World

    创建一个Windows application项目,然后可以调用里面的工具来生成代码. using System; using System.Collections.Generic; using Sy ...

  5. Java面向对象编程三大特性 --- 多态

    多态特性: 子类Child继承父类Father,我们可以编写一个指向子类的父类类型引用,该引用既可以处理父类Father对象,也可以处理子类Child对象,当相同的消息发送给子类或者父类对象时,该对象 ...

  6. 【洛谷 P4555】 [国家集训队]最长双回文串 (Manacher)

    题目链接 \(|S|<=10^5\),时间还是很宽松的. 允许我们使用线性/\(N\log N\)/甚至\(N \sqrt N\)的算法. 设\(l[i]\)表示以\(a[i]\)结尾的最长回文 ...

  7. 文本区 JTextArea 的使用

    文本区JTextArea是对多行文本进行编辑的组件,用空字符来控制文本的格式.eg:"\n"为换行,"\t"为插入一个Tab字符. 文本去JTextArea的常 ...

  8. Python 模拟SQL对文件进行增删改查

    #!/usr/bin/env python # _*_ coding:UTF-8 _*_ # __auth__: Dalhhin # Python 3.5.2,Pycharm 2016.3.2 # 2 ...

  9. Backbone Model 源码简谈 (版本:1.1.0 基础部分完毕)

    Model工厂   作为model的主要函数,其实只有12行,特别的简练 var Model = Backbone.Model = function(attributes, options) { va ...

  10. Map、Set、List初始化大小的影响

    import java.util.ArrayList; import java.util.HashMap; import java.util.HashSet; import java.util.Lis ...