es 数据 导出 到 MySQL

暂时没有找到直接 导出到 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 [email protected]*

从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);
?> 

原文地址:https://www.cnblogs.com/zhaohuanhuan/p/9197541.html

时间: 2024-08-01 09:06:20

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

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

POI是Apache的一套读MS文档的API,用它还是可以比较方便的读取Office文档的.目前支持Word,Excel,PowerPoint生成的文档,还有Visio和Publisher的. http://poi.apache.org/download.html 具体的用法可以查阅文档里面您的quickguide,我给出我自己的范例,从xls文件把数据导出到MySQL. 这里面我总是假定excel在第一个sheet并且第一行是字段名,能够自动从第一行读取字段名建立一个表然后导入数据. pack

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

从hive将数据导出到mysql http://abloz.com 2012.7.20 author:周海汉 在上一篇文章<用sqoop进行mysql和hdfs系统间的数据互导>中,提到sqoop可以让RDBMS和HDFS之间互导数据,并且也支持从mysql中导入到HBase,但从HBase直接导入mysql则不是直接支持,而是间接支持.要么将HBase导出到HDFS平面文件,要么将其导出到Hive中,再导出到mysql.本篇讲从hive中导出到mysql.从hive将数据导出到mysql 一

MSSQL数据导出到MYSQL

MSSQL数据导出到MYSQL 花了一天时间把MSSQL里的数据导出到MYSQL, 好麻烦,二个数据库都是阿里云买的云服务器. 先上阿里云控制面板,备份下MSSQL数据库,下载备份下来,在本地电脑上还原 2.本地MSSQL数据库上执行select * into aaa from order where createtime>='2018-11-12 00:00:00' and createtime<='2018-11-13 00:00:00', 把一天的数据导出到新表aaa中,其中aaa是不存

mysql数据导出权限问题

mysql数据导出的方法有非常多,比如mysqldump, mysql -e 'sql' > file, 这些都能够非常方便的导出数据,但是在使用普通用户导出数据的时候,出现了问题. 1 select * into outfile "file_path" from my_table 上面的语句也是mysql导出数据的一种方式,在使用普通用户运行语句时.出现了一下错误: 1 ERROR 1045 (28000): Access denied for user 'my_user'@'

MySQL数据导出与导入

发一篇基础的,关于MySQL数据导出导入的文章,目的有二: 1.备忘 2.供开发人员测试 工具 mysql/source 导入mysqldump 导出 应用举例 导出 导出全库备份到本地的目录 mysqldump -u$USER -p$PASSWD -h127.0.0.1 -P3306 --routines --default-character-set=utf8 --lock-all-tables --add-drop-database -A > db.all.sql 导出指定库到本地的目录(

用mapreduce实现将mysql数据导出到HDFS上

因为业务需要,需要将一批mysql数据导入到HBASE,现在先将数据从Mysql导出到HDFS. 版本:hadoop CDH4.5,Hbase-0.946 1.实体类 YqBean 是我的实体类,请根据自己需要修改,实体类需要 implements Writable, DBWritable. 2.MR实现 import java.io.IOException; import java.util.Iterator; import org.apache.hadoop.conf.Configurati

[Sqoop]将Hive数据表导出到Mysql

业务背景 mysql表YHD_CATEG_PRIOR的结构如下: -- Table "YHD_CATEG_PRIOR" DDL CREATE TABLE `YHD_CATEG_PRIOR` ( `category_id` int(11) NOT NULL COMMENT '类目ID', `category_name` varchar(250) DEFAULT NULL COMMENT '类目名称', `category_level` int(11) DEFAULT '0' COMMEN

mysql的数据导出方法

mysql的数据导出几种方法 从网上找到一些问题是关于如何从MySQL中导出数据,以便用在本地或其它的数据库系统之上:以及 将现有数据导入MySQL数据库中. 数据导出 数据导出主要有以下几种方法: 使用select into outfile "filename"语句 使用mysqldump实用程序 使用select into outfile "filename"语句 可以在mysql的命令行下或在php程序中执行它.我下面以在mysql命令行下为例.在php中使用

mysql数据导出到excel以及相关计算

mysql 查询出数据之后, 可以选择导出文件 默认是csv文件  如果是整数类型的数据 可以CONCAT('\'', filed) 多加个'就可以变成文本了, 然后以文本编辑器打开csv文件 把'等字符替换为空字符串. 新建一个excel文件,找到数据-->自文本,选择下一步 格式为文本  确定即可 一些基本的excel函数: 计算某个字符或数字等的个数:=COUNTIF(A:A,"测试") 就是在A列的'测试'这个字符串出现的个数 根据身份证号计算性别:=IF(MOD(MID