1、建立hive表
CREATE TABLE `wb_tmp`(
`surface` string,
`radiation` string,
`loader_id` string)
ROW FORMAT DELIMITED
FIELDS TERMINATED BY ','
STORED AS INPUTFORMAT
'org.apache.hadoop.mapred.TextInputFormat'
OUTPUTFORMAT
'org.apache.hadoop.hive.ql.io.HiveIgnoreKeyTextOutputFormat'
LOCATION
'hdfs://ffcs/user/projectquene001/publictest/'
TBLPROPERTIES (
'transient_lastDdlTime'='154762891');
2、临时加载es-hadoop的接口jar依赖
(添加jar包 只对当前会话有效,jar包路径可以自己用hdfs - put 命令上传)
add jar hdfs://ffcs/user/feilongv3/public/elasticsearch-hadoop-6.3.2.jar
3、建立hive2es外表
create external table ES_WB(
surface string,
radiation string,
loader_id string)
STORED BY 'org.elasticsearch.hadoop.hive.EsStorageHandler'
TBLPROPERTIES(
'es.resource' = 'es_mytest/es_mytest', -- es中的索引名称
'es.nodes'='192.168.12.141',
'es.port'='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');
4、开始同步写入
insert overwrite table es_wb select surface,radiation,loader_id from wb_tmp;