一、准备jar包:可以去mvn仓库下载
elasticsearch-hadoop-6.3.1.jar
二、 进入hive添加jar
hive>add jar /mnt/elasticsearch-hadoop-6.3.1.jar
三、准备数据
[root@master 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
查看结果: