环境:hadoop2.6.4、hive1.2.1、elasticsearch7.6.1、centos7
1、下载与es版本一致的es-hadoop版本
wget https://artifacts.elastic.co/downloads/elasticsearch-hadoop/elasticsearch-hadoop-7.6.1.zip
2、解压,上传到hdfs指定目录
unzip elasticsearch-hadoop-7.6.1.zip
hdfs dfs -mkdir /user/test/es_hadoop/
hdfs dfs -put elasticsearch-hadoop-hive-7.6.1.jar /user/test/es_hadoop/
3、hive添加jar引用
add jar hdfs://hadoop.m1:9000/user/test/es_hadoop/elasticsearch-hadoop-hive-7.6.1.jar;
4、创建外部表
CREATE EXTERNAL TABLE elastic_test_table(
id bigint,
name string,
length decimal(4,2),
birth_day string,
create_time string
)
STORED BY 'org.elasticsearch.hadoop.hive.EsStorageHandler'
TBLPROPERTIES(
'es.index.auto.create'='true',--自动创建索引
'es.index.read.missing.as.empty'='true', --防止查询为空值报错
'es.mapping.id'='id', --指定hive的字段对应es索引的_id值
'es.resource'='es_test_table/_doc', --ES中的索引
'es.net.http.auth.pass'='elastic', --ES密码
'es.net.http.auth.user'='elastic', --ES登录名
'es.nodes'='172.16.227.235,172.16.227.236,172.16.227.229', --ES地址
'es.port'='9200',
'es.nodes.wan.only'='true',
'es.nodes.discovery' = 'false',
'es.read.metadata'='true'
);
5、插入数据
INSERT overwrite TABLE elastic_test_table VALUES (1, "zhangsan", 20,"birth_day", "create_time");
6、在kibana客户端查询
GET /es_test_table/_doc/_search?q=id:<10
结果如下: