1. 程式人生 > >Hive數據導入Elasticsearch

Hive數據導入Elasticsearch

fields png txt ring 數據表 inf ESS handler def

一、準備jar包:可以去mvn倉庫下載

elasticsearch-hadoop-6.3.1.jar

二、 進入hive添加jar

hive>add jar /mnt/elasticsearch-hadoop-6.3.1.jar

三、準備數據

[[email protected] mnt]# cat test.txt 
111,aaa
222,bbb
333,ccc

四、創建與Elasticsearch對接test外部表

create table test(key string,value string) STORED BY org.elasticsearch.hadoop.hive.EsStorageHandler
TBLPROPERTIES(es.resource = test/user, es.nodes=192.168.200.100, es.port=9200, es.nodes.wan.only=true);

技術分享圖片

創建源數據表test1

hive> CREATE TABLE test1(key string,value string)  row format delimited fields terminated by , stored as textfile;
OK
Time taken: 0.266 seconds

hive> load data local inpath ‘/mnt/test.txt‘ into table test1;

Loading data to table default.test1
OK

加載MR結果到HIVE

技術分享圖片

查看結果:

技術分享圖片

技術分享圖片

技術分享圖片

Hive數據導入Elasticsearch