mac环境 整合hive和elasticsearch

上一篇介绍了mac下安装hive,《mac环境下安装hive》,写完后有同学问hive的查询速度太慢了,能不能接近实时检索?大家知道hive提供了方便的类sql语言hql,但是底层仍然是通过mr进行离线运算(见下图),业内也有一些类似于impala的工具,但还是不能和关系数据库媲美,这时就可以通过es和hive进行整合来实现需求。希望本文能为大家带来帮助。

《mac环境 整合hive和elasticsearch》

安装elasticsearch

1、brew install elasticsearch

2、启动elasticsearch ,执行elasticsearch

3、访问127.0.0.1:9200

《mac环境 整合hive和elasticsearch》

hive整合es:

1、下载http://jcenter.bintray.com/org/elasticsearch/elasticsearch-hadoop/找到和es匹配的jar文件

2、hive -hiveconf hive.aux.jars.path=file:///usr/local/Cellar/hive/2.1.1/libexec/lib/elasticsearch-hadoop-5.5.2.jar

或者在hive-site.xml中增加:

hive.aux.jars.path

file:///usr/local/Cellar/hive/2.1.1/libexec/lib/elasticsearch-hadoop-5.5.2.jar

3、创建表

CREATE EXTERNAL TABLE employee  (id INT, name STRING) STORED BY ‘org.elasticsearch.hadoop.hive.EsStorageHandler’ TBLPROPERTIES(‘es.resource’ = ’employees/list’,’es.index.auto.create’ = ‘true’,’es.nodes’ = ‘localhost’,’es.port’ = ‘9200’,’es.mapping.id’ = ‘id’,’es.write.operation’=’upsert’);

4、创建源表

CREATE TABLE employee_source  (id INT, name STRING) ROW FORMAT DELIMITED FIELDS TERMINATED BY ‘,’;

5、导入数据

LOAD DATA LOCAL INPATH ‘/Users/yinxiaokai/Documents/employee_source.log’ OVERWRITE INTO TABLE employee_source;

employee_source.log文件内容:

1,jim

2,kate

3,tom

4,mike

6、将源表数据导入测试表

INSERT OVERWRITE TABLE employee  SELECT s.id, s.name FROM employee_source s;

7、验证:

http://localhost:9200/employees/list/_search

补充:

es原生的展示不是很方便,建议同学们安装head插件

1、 git clone git://github.com/mobz/elasticsearch-head.git

2、cd elasticsearch-head

3、brew install node

4、npm -g install grunt

5、修改es yml配置文件,增加:

http.cors.enabled: true

http.cors.allow-origin: “*”

6、grunt server

7、访问http://localhost:9100

ok,至此hive和es的整合结束。

    原文作者:尹小凯
    原文地址: https://www.jianshu.com/p/8ae12fbcd1d2
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞