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 ...
随机推荐
- Vim实用小技巧
Vim实用小技巧 一些网络上质量较高的Vim资料 从我07年接触Vim以来,已经过去了8个年头,期间看过很多的Vim文章,我自己觉得非常不错,而且创作时间也比较近的文章有如下这些. Vim入门 目前为 ...
- Zepto
移动开发流量省起来之Zepto 事情是这样的:最近开发的一个手机网站客户反应访问起来特别慢,刷了半天才能看到页面,然后问我们是不是网站出问题了.于是我赶紧找了各种手机测试一下,没有问题,首先排除程序错 ...
- Effective C++:规定34:区分接口继承和实现继承
(一个) class Shape { public: virtual void draw() const = 0; virtual void error(const string& msg); ...
- 请确保在编译时已将“AjaxControlToolkit.Properties.Resources.NET4.resources”正确嵌入或链接到程序集“AjaxControlToolkit”
原文:请确保在编译时已将"AjaxControlToolkit.Properties.Resources.NET4.resources"正确嵌入或链接到程序集"AjaxC ...
- 我看PS求职简历照
看新闻<大学生求职简历照片不PS 连面试机会都没有>,忍不住也谈些自己的看法. 个人意见,尽量求真,这个求真要有平时努力的保证.长相一般的,知道自己是普通一员,按普通的方式行事就可以.即使 ...
- Nginx均衡负载(IP_HASH)未生效
由于公司业务的发展,单台服务器已经无法满足并发和用户的需求,所以只能通过水平拓展的方式加机器来解决,线上采用的是Nginx+Tomcat集群的方式来解决.由于当前业务量不是很大,而且由于之前代码的问题 ...
- CRT
G - 中国剩余定理 Time Limit:1000MS Memory Limit:10000KB 64bit IO Format:%I64d & %I64u Submit S ...
- INNO SETUP卸载程序中加入自定义窗体
原文:INNO SETUP卸载程序中加入自定义窗体 [Setup] AppName=My Program AppVerName=My Program v.1.2 DefaultDirName={pf} ...
- centos6.4搭建apache+mysql+php环境
最近用php做的项目到了项目部署的时候,服务器为centos6.4系统,为了快捷部署,采用yum安装部署 大部分内容参考博客 http://blog.sina.com.cn/s/blog_c02ed ...
- 12个很少被人知道的CSS事实
之前没有认真的研究过,padding-bottom的值如果是百分比,那么它的实际值是根据父类的宽度来调整的.我还以为是根据这个元素的本身的宽度来定义呢?汗..padding-top/padding-l ...