ES数据导入导出
ES数据导入导出
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
|
''' Export and Import ElasticSearch Data. Simple Example At __main__ @author: wgzh159@163.com @note: uncheck consistency of data, please do it by self ''' import json import os import sys import time import urllib2 reload (sys) sys.setdefaultencoding( 'utf-8' ) # @UndefinedVariable class exportEsData(): size = 10000 def __init__( self , url,index, type ): self .url = url + "/" + index + "/" + type + "/_search" self .index = index self . type = type def exportData( self ): print ( "export data begin..." ) begin = time.time() try : os.remove( self .index + "_" + self . type + ".json" ) except : os.mknod( self .index + "_" + self . type + ".json" ) msg = urllib2.urlopen( self .url).read() print (msg) obj = json.loads(msg) num = obj[ "hits" ][ "total" ] start = 0 end = num / self .size + 1 while (start<end): msg = urllib2.urlopen( self .url + "?from=" + str (start * self .size) + "&size=" + str ( self .size)).read() self .writeFile(msg) start = start + 1 print ( "export data end!!!\n\t total consuming time:" + str (time.time() - begin) + "s" ) def writeFile( self ,msg): obj = json.loads(msg) vals = obj[ "hits" ][ "hits" ] try : f = open ( self .index + "_" + self . type + ".json" , "a" ) for val in vals: a = json.dumps(val[ "_source" ],ensure_ascii = False ) f.write(a + "\n" ) finally : f.flush() f.close() class importEsData(): def __init__( self ,url,index, type ): self .url = url + "/" + index + "/" + type self .index = index self . type = type def importData( self ): print ( "import data begin..." ) begin = time.time() try : f = open ( self .index + "_" + self . type + ".json" , "r" ) for line in f: self .post(line) finally : f.close() print ( "import data end!!!\n\t total consuming time:" + str (time.time() - begin) + "s" ) def post( self ,data): req = urllib2.Request( self .url,data,{ "Content-Type" : "application/json; charset=UTF-8" }) urllib2.urlopen(req) if __name__ = = '__main__' : ''' Export Data e.g. URL index type exportEsData("http://10.100.142.60:9200","watchdog","mexception").exportData() export file name: watchdog_mexception.json ''' #exportEsData("http://10.100.142.60:9200","watchdog","mexception").exportData() exportEsData( "http://10.100.142.60:9200" , "watchdog" , "mexception" ).exportData() ''' Import Data *import file name:watchdog_test.json (important) "_" front part represents the elasticsearch index "_" after part represents the elasticsearch type e.g. URL index type mportEsData("http://10.100.142.60:9200","watchdog","test").importData() ''' #importEsData("http://10.100.142.60:9200","watchdog","test").importData() importEsData( "http://10.100.142.60:9200" , "watchdog" , "test" ).importData() |
ES数据导入导出的更多相关文章
- Elasticsearchdump 数据导入/导出
一.安装过程 Elasticsearchdump 仓库地址,详细使用情况 当前工具主要是用来对ES中的数据进行数据导入/导出,以及对数据迁移相关,使用elasticdump工具需要使用到npm,所以需 ...
- ITTC数据挖掘平台介绍(五) 数据导入导出向导和报告生成
一. 前言 经过了一个多月的努力,软件系统又添加了不少新功能.这些功能包括非常实用的数据导入导出,对触摸进行优化的画布和画笔工具,以及对一些智能分析的报告生成模块等.进一步加强了平台系统级的功能. 马 ...
- 从零自学Hadoop(16):Hive数据导入导出,集群数据迁移上
阅读目录 序 导入文件到Hive 将其他表的查询结果导入表 动态分区插入 将SQL语句的值插入到表中 模拟数据文件下载 系列索引 本文版权归mephisto和博客园共有,欢迎转载,但须保留此段声明,并 ...
- oracle数据导入/导出
Oracle数据导入导出imp/exp 功能:Oracle数据导入导出imp/exp就相当与oracle数据还原与备份. 大多情况都可以用Oracle数据导入导出完成数据的备份和还原(不会造成数据 ...
- Oracle数据导入导出
Oracle数据导入导出imp/exp 在oracle安装目录下有EXP.EXE与IMP.EXE这2个文件,他们分别被用来执行数据库的导入导出.所以Oracle数据导入导出imp/exp就相当与ora ...
- SQL SERVER 和ACCESS的数据导入导出
//批量导入Access string filepath = Server.MapPath("student.mdb"); stri ...
- 关于 Oracle 的数据导入导出及 Sql Loader (sqlldr) 的用法
在 Oracle 数据库中,我们通常在不同数据库的表间记录进行复制或迁移时会用以下几种方法: 1. A 表的记录导出为一条条分号隔开的 insert 语句,然后执行插入到 B 表中2. 建立数据库间的 ...
- Hive 实战(1)--hive数据导入/导出基础
前沿: Hive也采用类SQL的语法, 但其作为数据仓库, 与面向OLTP的传统关系型数据库(Mysql/Oracle)有着天然的差别. 它用于离线的数据计算分析, 而不追求高并发/低延时的应用场景. ...
- Winform开发框架之通用数据导入导出操作的事务性操作完善
1.通用数据导入导出操作模块回顾 在我的Winfrom开发框架里面,有一个通用的导入模块,它在默默处理这把规范的Excel数据导入到不同的对象表里面,一直用它来快速完成数据导入的工作.很早在随笔< ...
随机推荐
- c#将数据导出到excel中
DataTable dt = new BLL.T_Expiry().GetAllList().Tables[0];//查询数据 string FileName = "T_Users.xl ...
- MFC对话框编程详细学习笔记
因最近研究工作要用到MFC,故再次重温了孙鑫老师的MFC对话框编程,因所用的编译软件为VS2008,与视频中孙老师使用的VC++6.0有很大出入,造成很大不便,我通过各方查找,实现了VS2008相对应 ...
- ABP的新旧版本
新版本 https://abp.io/documents/abp/latest/Index https://github.com/abpframework/abp ABP is an open sou ...
- JS-ValidForm:介绍
ylbtech-JS-ValidForm:介绍 1.返回顶部 1. 关于Validform Validform:一行代码搞定整站的表单验证! 1 $(".demoform").Va ...
- Python常用模块系列
1.时间模块 import time,datetime # print(time.time()) #时间戳 # print(time.strftime("%Y-%m-%d %X") ...
- haproxy附加
1.安装haproxy yum -y install haproxy 2.编写文件 vim /etc/haproxy/haproxy.cfg
- springMvc注册时图形验证码完整代码与详细步骤``````后续更新注册时对密码进行加密
第一使用 画图软件制作图片 ,文件名就是验证码 ------用户的实体类 import java.util.Date; public class Member { private in ...
- spring源码解读之 JdbcTemplate源码
原文:https://blog.csdn.net/songjinbin/article/details/19857567 在Spring中,JdbcTemplate是经常被使用的类来帮助用户程序操作数 ...
- idea部署tomcat项目时,在项目里打断点不能拦截
以下内容都是基于我自己的项目(如未解决道友们的问题,请别介意) idea部署tomcat项目时,在项目里打断点不能拦截,工作中遇到的问题,记录一下(tomcat6) 当项目的以下内容配置完毕后,启动项 ...
- Pytest参数传递
import pytest@pytest.fixture()def login_r(open_browser):#调用login时,发现需要先打开浏览器,所以改成先打开浏览器,在登陆 print('输 ...