使用es-hadoop同步hive和es之间数据

环境: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

结果如下:

  • 0
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值