我是靠谱客的博主 舒心自行车,这篇文章主要介绍hive与elasticsearch的数据交互版本:elasticsearch-2.4.1一、使用hive向elasticsearch中写数据二、使用elasticsearch向hive中写数据,现在分享给大家,希望可以做个参考。

版本:elasticsearch-2.4.1

一、使用hive向elasticsearch中写数据

第一步、创建你想要的索引curl -XPOST "http://000.000.000.000:9200/test_tag" 
第二步、创建hive外部表:
复制代码
1
2
3
4
--关闭Hive推测执行,执行INSERT SET hive.mapred.reduce.tasks.speculative.execution = false; SET mapreduce.map.speculative = false; SET mapreduce.reduce.speculative = false;

复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
hive -e" add jar hdfs:/opt/data/jar/elasticsearch-hadoop-2.4.3.jar; add jar hdfs:/opt/data/jar/org.apache.commons.httpclient_3.1.0.v201012070820.jar; --org.apache.commons.httpclient_3.1.0.v201012070820.jar这个jar包一般是不用加的,除非在报httpclient相关错误的时候才加 use ods; create external table if not exists app.test_tag( complaint_id string, tag_name string, classification string, sub_classification string ) STORED BY 'org.elasticsearch.hadoop.hive.EsStorageHandler' TBLPROPERTIES('es.nodes'='000.000.000.000','es.resource' = 'test_tag/defect_recommend_tag'); --es.resource斜线前面为索引(这里索引与hive表同名),斜线后面为mapping名称。mapping可以不用事先建好(建议自定义一个),当数据插入时会自动根据数据类型创建mapping。 insert overwrite table app.test_tag select complaint_id,tag_name,classification,sub_classification from app.src_test_tag;"

程序执行完毕,就可以在es里看到数据了。

二、使用elasticsearch向hive中写数据

第一步、创建hive外部表:
复制代码
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
hive -e" add jar hdfs:/opt/data/jar/elasticsearch-hadoop-2.4.3.jar; add jar hdfs:/opt/data/jar/org.apache.commons.httpclient_3.1.0.v201012070820.jar; --org.apache.commons.httpclient_3.1.0.v201012070820.jar这个jar包一般是不用加的,除非在报httpclient相关错误的时候才加 use ods; create external table if not exists app.test_tag( complaint_id string, tag_name string, classification string, sub_classification string ) STORED BY 'org.elasticsearch.hadoop.hive.EsStorageHandler' TBLPROPERTIES('es.nodes'='000.000.000.000','es.resource' = 'test_tag/defect_recommend_tag'); --es.resource斜线前面为索引(这里索引与hive表同名),斜线后面为mapping名称。mapping可以不用事先建好(建议自定义一个),当数据插入时会自动根据数据类型创建mapping。
必须指出明确的字段 select complaint_id from app.test_tag; 不可以使用 select * from app.test_tag;










最后

以上就是舒心自行车最近收集整理的关于hive与elasticsearch的数据交互版本:elasticsearch-2.4.1一、使用hive向elasticsearch中写数据二、使用elasticsearch向hive中写数据的全部内容,更多相关hive与elasticsearch内容请搜索靠谱客的其他文章。

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

评论列表共有 0 条评论

立即
投稿
返回
顶部