hive 数据导入 es

教程 犀牛 ⋅ 于 2021-06-05 11:13:53 ⋅ 1601 阅读

es-hadoop插件

上传es-hadoop插件到集群

准备hive数据

-- 连接hive
beeline -u "jdbc:hive2://worker-1:10000/;principal=hive/worker-1@HAINIU.COM"
-- 创建临时表
create table if not exists xiniu.hivetable(
    pk string,
    col1 int,
    col2 boolean,
    col3 timestamp,
    col4 string
)
comment 'hive表'
row format delimited fields terminated by '\t'
;
-- 加载数据
load data inpath '/eslib/testfile' into table xiniu.hivetable;

导入hive数据到es

  • 上传es-hadoop jar包
hadoop fs -put /opt/elasticsearch-hadoop-7.13.1.jar /eslib/
  • 加载es-hadoop jar包
add jar hdfs:///eslib/elasticsearch-hadoop-7.13.1.jar
  • 创建es的hive外表
CREATE EXTERNAL TABLE xiniu.hive2es(
pk string,
col1 string,
col2 string,
col3 string,
col4 string
)STORED BY 'org.elasticsearch.hadoop.hive.EsStorageHandler'
TBLPROPERTIES('es.resource'='hivemappinges/_doc',
'es.nodes'='worker-1:9200,worker-2:9200,worker-3:9200',
'es.index.auto.create'='TRUE',
'es.index.refresh_interval' = '-1',
'es.index.number_of_replicas' = '0',
'es.batch.write.retry.count' = '6',
'es.batch.write.retry.wait' = '60s',
'es.mapping.name' = 'pk:pk,col1:col1,col2:col2,col3:col3,col4:col4'
);
  • 插入数据到es的hive外表
INSERT OVERWRITE TABLE xiniu.hive2es SELECT pk,col1,col2,col3,col4 FROM xiniu.hivetable;

file

file

file

版权声明:原创作品,允许转载,转载时务必以超链接的形式表明出处和作者信息。否则将追究法律责任。来自海汼部落-犀牛,http://hainiubl.com/topics/75637
成为第一个点赞的人吧 :bowtie:
回复数量: 0
    暂无评论~~
    • 请注意单词拼写,以及中英文排版,参考此页
    • 支持 Markdown 格式, **粗体**、~~删除线~~、`单行代码`, 更多语法请见这里 Markdown 语法
    • 支持表情,可用Emoji的自动补全, 在输入的时候只需要 ":" 就可以自动提示了 :metal: :point_right: 表情列表 :star: :sparkles:
    • 上传图片, 支持拖拽和剪切板黏贴上传, 格式限制 - jpg, png, gif,教程
    • 发布框支持本地存储功能,会在内容变更时保存,「提交」按钮点击时清空
    Ctrl+Enter