环境:
es 2.2.1
hadoop 2.7.3
hive 2.2.1
利用插件讲hive里面的数据写入es
在es可下载插件 elasticsearch-hadoop-2.2.0.jar
比如要把basic_table里的数据写到es里面
1、首先则hive里面建表
drop table if exists basic_table_es;
create external table basic_table_es(
uid string,
name string,
age bigint,
score double
)STORED BY 'org.elasticsearch.hadoop.hive.EsStorageHandler'
TBLPROPERTIES('es.nodes' = '10.202.8.142:9200','es.index.auto.create' = 'true','es.resource' = 'basic_table_es201706/b',
'es.read.metadata' = 'true','es.mapping.id' = 'uid');
es.mapping.id=id 表示es里记录的id去表里的id字段
还可以加入mapping
es.mapping.names’ = userid:uid,name :name,age:age,score:score(我一般喜欢提交用命令建好索引,就不加这个了)
2往es表里写数据
add jar elasticsearch-hadoop-2.2.0.jar;
insert into table basic_table_es select * from basic_table ;
注意:
新建的hive表里不能有int类型的字段,不然写入es的时候会报错:
Failed with exception java.io.IOException:org.apache.hadoop.hive.ql.metadata.HiveException: java.lang.ClassCastException: org.apache.hadoop.io.LongWritable cannot be cast to org.apache.hadoop.io.IntWritable
解决办法:把int改为bigint