我是靠谱客的博主 忐忑乐曲,这篇文章主要介绍使用hive访问elasticsearch的数据,现在分享给大家,希望可以做个参考。

使用hive访问elasticsearch的数据

1.配置
将elasticsearch-hadoop-2.1.1.jar拷贝到hive/lib

复制代码
1
hive -hiveconf hive.aux.jars.path=/usr/local/hive-1.2.1/lib/elasticsearch-hadoop-2.1.1.jar

或者配置:
hive-site.xml

复制代码
1
2
3
4
5
<property> <name>hive.aux.jars.path</name> <value>file:///usr/local/hive-1.2.1/lib/elasticsearch-hadoop-2.1.1.jar</value> <description>A comma separated list (with no spaces) of the jar files</description> </property>

2.创建外表

CREATE EXTERNAL TABLE achi_ex(
vid string,
dtime timestamp,
platid bigint)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ‘t’
LINES TERMINATED BY ‘n’
STORED BY ‘org.elasticsearch.hadoop.hive.EsStorageHandler’
TBLPROPERTIES(‘es.resource’ = ‘db_1/achi’,
‘es.index.auto.create’ = ‘true’);

*hive 中的timestamp和ES中的date相互映射

3.导入数据
insert overwrite table achi_ex select * from achi;

4.测试

select * from achi_ex limit 10;

错误:

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

hive表中field类型为int时,映射到es中变成long,所以会报此错误。将hive表中int改为bigint即可。

CREATE EXTERNAL TABLE achi_ex(
vid string,
dtime timestamp,
platid bigint)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ‘t’
LINES TERMINATED BY ‘n’
STORED BY ‘org.elasticsearch.hadoop.hive.EsStorageHandler’
TBLPROPERTIES(‘es.resource’ = ‘db_1/achi’,
‘es.mapping.names’ = ‘vid:vID,dtime:dTime,platid:PlatID
‘);

最后

以上就是忐忑乐曲最近收集整理的关于使用hive访问elasticsearch的数据的全部内容,更多相关使用hive访问elasticsearch内容请搜索靠谱客的其他文章。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(92)

评论列表共有 0 条评论

立即
投稿
返回
顶部