Hive整合ElasticSearch

Hive整合ElasticSearch

作用:直接将Hive数据入到Es中

  1. 创建Index
PUT bank_2 
{
  "settings": {
    "number_of_shards": 5
    , "number_of_replicas": 1
  }
}
  1. 创建Type的Mapping
PUT bank_2/_doc/_mapping
{
  "properties": {
    "fid":{
      "type": "keyword"
    },
    "tid":{
      "type": "keyword"
    },
    "counts":{
      "type": "long"
    },
    "sums":{
      "type": "double"
    },
    "years":{
      "type": "integer"
    }
  }
}
  1. 下载es-hive相关Jar包,入到HDFS中
wget https://artifacts.elastic.co/downloads/elasticsearch-hadoop/elasticsearch-hadoop-6.6.0.zip
  1. Hive添加相关JAR包
hive > add jar hdfs://gl0:9000/jars/elasticsearch-hadoop-hive-6.5.1.jar;
hive > add jar hdfs://gl0:9000/jars/commons-httpclient-3.1.jar;
  1. 创建ES外部表
drop table yin_hang_ce_shi.elastic_bank_2;
CREATE EXTERNAL TABLE yin_hang_ce_shi.elastic_bank_2(
   idcard string,
   fid string,
   tid string,
   counts bigint,
   sums double,
   years int
)
STORED BY 'org.elasticsearch.hadoop.hive.EsStorageHandler'
TBLPROPERTIES('es.resource'='${index}',
'es.nodes'='${ips}',
'es.port'='9200',
'es.index.auto.create'='TRUE',
'es.mapping.id' = '${索引ID字段}'
);
  1. 添加数据
insert into yin_hang_ce_shi.elastic_bank_2 (select * from yin_hang_ce_shi.table);
  • 1
    点赞
  • 3
    收藏
    觉得还不错? 一键收藏
  • 5
    评论
评论 5
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值