elasticsearch data importing
ElasticSearch stores each piece of data in a document.
That's what I need.
Using the bulk API.
Transform the raw data file from data.json to be new_data.json .
And then do this to import data to ElasticSearch :
curl -s -XPOST 'localhost:9200/_bulk' --data-binary @new_data.json
For example, I now have a raw JSON data file as following:
The file data.json
{"key1":"valueA_row_1","key2":"valueB_row_1","key3":"valueC_row_1"}
{"key1":"valueA_row_2","key2":"valueB_row_2","key3":"valueC_row_2"}
{"key1":"valueA_row_3","key2":"valueB_row_3","key3":"valueC_row_3"}
Then I need to import these data to elasticsearch. So I have to manipulate this file by naming its index and type.
A new file will be created new_data.json
{"index":{"_index":"myindex1","_type":"mytype1"}}
{"key1":"valueA_row_1","key2":"valueB_row_1","key3":"valueC_row_1"}
{"index":{"_index":"myindex1","_type":"mytype1"}}
{"key1":"valueA_row_2","key2":"valueB_row_2","key3":"valueC_row_2"}
{"index":{"_index":"myindex1","_type":"mytype1"}}
{"key1":"valueA_row_3","key2":"valueB_row_3","key3":"valueC_row_3"}
There are information above each of the data line in the file new_data.json
And if the JSON data file contains data those are not in the same _index or _type, just change the {"index":{"_******** line
Here is an example of a valid JSON file for elasticsearch.
full_data.json
{"index":{"_index":"myindex1","_type":"mytype1"}}
{"key1":"value1","key2":"value2","key3":"value3"}
{"index":{"_index":"myindex1","_type":"mytype1"}}
{"key1":"abcde","key2":"efg","key3":"klm"}
{"index":{"_index":"myindex2","_type":"mytype2"}}
{"newkey":"newvalue"}
Notice that : There are 2 indexes in the file above. They are myindex1 and myindex2
And the data schema in index myindex2 is different from that in index myindex1 .
That's why it's so important to have so many lines of {"index":{"_******** in the new data file.
-----
Now I am coding a python scripe to manipulate with some raw JSON data files.
Let's assume each line of the JSON data file are in the same schema. And I will do this to generate the schema out.
example_raw_data.json
import sys def get_schema():
"""
"""
return None if __name__ == "__main__":
print(get_schema)
-------------Updated on 27th Nov. 2015 ----------
I solved this by inventing a new wheel
You can check this out:
https://github.com/xros/json-py-es
-------------Updated on 28th Nov. 2015 at 01:33 A.M. ----------
pip install jsonpyes
I wrote this module and it works!
Happy hacking!
elasticsearch data importing的更多相关文章
- 【Big Data - ELK】ELK(ElasticSearch, Logstash, Kibana)搭建实时日志分析平台
摘要: 前段时间研究的Log4j+Kafka中,有人建议把Kafka收集到的日志存放于ES(ElasticSearch,一款基于Apache Lucene的开源分布式搜索引擎)中便于查找和分析,在研究 ...
- [Big Data - ELK] ELK(ElasticSearch, Logstash, Kibana)搭建实时日志分析平台
ELK平台介绍 在搜索ELK资料的时候,发现这篇文章比较好,于是摘抄一小段: 以下内容来自: http://baidu.blog.51cto.com/71938/1676798 日志主要包括系统日志. ...
- ElasticsearchException: java.io.IOException: failed to read [id:0, file:/data/elasticsearch/nodes/0/_state/global-0.st]
from : https://www.cnblogs.com/hixiaowei/p/11213143.html 1.以前装过elasticsearch,重新安装elastic search ,报错 ...
- Ubuntu 14.04中Elasticsearch集群配置
Ubuntu 14.04中Elasticsearch集群配置 前言:本文可用于elasticsearch集群搭建参考.细分为elasticsearch.yml配置和系统配置 达到的目的:各台机器配置成 ...
- ElasticSearch 5学习(2)——Kibana+X-Pack介绍使用(全)
Kibana是一个为 ElasticSearch 提供的数据分析的 Web 接口.可使用它对日志进行高效的搜索.可视化.分析等各种操作.Kibana目前最新的版本5.0.2,回顾一下Kibana 3和 ...
- docker run elasticsearch
docker run -d --name=esNode1 -p 9200:9200 -p 9300:9300 elasticsearch:2.3 -Des.network.publish_host=& ...
- ElasticSearch详解与优化设计
简介 概念 安装部署 ES安装 数据索引 索引优化 内存优化 1简介 ElasticSearch(简称ES)是一个分布式.Restful的搜索及分析服务器,设计用于分布式计算:能够达到实时搜索,稳定, ...
- 分布式搜索引擎Elasticsearch的简单使用
官方网址:https://www.elastic.co/products/elasticsearch/ 一.特性 1.支持中文分词 2.支持多种数据源的全文检索引擎 3.分布式 4.基于lucene的 ...
- 【转】ELK(ElasticSearch, Logstash, Kibana)搭建实时日志分析平台
[转自]https://my.oschina.net/itblog/blog/547250 摘要: 前段时间研究的Log4j+Kafka中,有人建议把Kafka收集到的日志存放于ES(ElasticS ...
随机推荐
- CSS3 制作向左、向右及关闭图标的效果
先看一下效果 1.鼠标移入前的效果 2.鼠标移入的效果 3.制作步骤如下: 轮廓的CSS,就是利用圆角和宽度高度,制作出一个圆: <style> /*显示方式为 inline-block* ...
- 我的MYSQL学习心得(十)
原文:我的MYSQL学习心得(十) 我的MYSQL学习心得(十) 我的MYSQL学习心得(一) 我的MYSQL学习心得(二) 我的MYSQL学习心得(三) 我的MYSQL学习心得(四) 我的MYSQL ...
- Windows socket之最简单的socket程序
原文:Windows socket之最简单的socket程序 最简单的服务器的socket程序流程如下(面向连接的TCP连接 ): 1. WSAStartup(); 初始化网络库的使用. 2. soc ...
- 日期格式化{0:yyyy-MM-dd HH:mm:ss.fff}和{0:yyyy-MM-dd hh:mm:ss.fff}的区别
原文:日期格式化{0:yyyy-MM-dd HH:mm:ss.fff}和{0:yyyy-MM-dd hh:mm:ss.fff}的区别 {0:yyyy-MM-dd HH:mm:ss.fff}:使用24小 ...
- 一步一步写算法(之prim算法 下)
原文:一步一步写算法(之prim算法 下) [ 声明:版权所有,欢迎转载,请勿用于商业用途. 联系信箱:feixiaoxing @163.com] 前两篇博客我们讨论了prim最小生成树的算法,熟悉 ...
- 判断小数点位数不超过2位的JS代码和在删除确认框里面插JS代码
<script type="text/javascript"> function checkDecimals(){ var decallowed = 2; var re ...
- ASP.NET中 RegularExpressValidator(正则验证)的使用
原文:ASP.NET中 RegularExpressValidator(正则验证)的使用 ylbtech-ASP.NET-Control-Validator: RegularExpressValida ...
- Ubuntu中改变文件的默认打开方式
其实最简单的方法是右键,在属性中修改,不过这样做没啥意义. ubuntu中与文件的打开方式相关的配置文件有四个: /etc/gnome/defaults.list 这是全局配置文件 /usr/shar ...
- 基于Quqrtz.NET 做的任务调度管理工具
基于Quqrtz.NET 做的任务调度管理工具 国庆前,需求让我看了一下任务调度的数据表设计.和之前一样,有100多个字段,p1 ~ p100, 我说这是干嘛啊!按这写,写死去了! 然后在网上搜了一下 ...
- Grunt使用入门
Grunt使用入门 (by vczero) 一.前言 项目中一直在使用Grunt,只是对Grunt的基本使用,却未系统的总结过.为什么要构建工具?一句话:自动化.对于需要反复重复的任务,例如压缩(mi ...