一 hive导入es

1 创建hive-es映射表

CREATE EXTERNAL TABLE hive_es.re_run_test2(
id STRING
,test STRING)
STORED BY 'org.elasticsearch.hadoop.hive.EsStorageHandler'
TBLPROPERTIES('es.resource' = 're_run_test2/test', 
'es.nodes'='172.16.98.113,172.16.98.149,172.16.98.150,172.16.98.151,172.16.98.152',
'es.port'='9200',
'es.mapping.id' ='id')

注:

1.

es.resource对应es中的index/type

2.

1.es.mapping.names为hive和es字段名映射关系。
2.如果hive表和es表字段名完全一致,可以省略此参数。
3.hive中字段名不区分大小写,元数据寸的全是小写;es中字段大小写敏感,如果es中字段名出现大写,需认真填写。
4.es中_id为自动生成,如若需要覆盖,需加参数'es.mapping.id'='id'

2 先导入es映射表相关jar包

add jar /opt/cloudera/parcels/CDH-6.3.2-1.cdh6.3.2.p0.1605554/lib/hive/auxlib/elasticsearch-hadoop-6.3.0.jar;
add jar /data/jar/httpclient-4.5.5.jar;
add jar /data/jar/org.apache.commons.httpclient.jar;

3 向映射表insert数据

二 es导入hive

1 建hive映射表

CREATE EXTERNAL TABLE hive_es.cty_test5(
addTime string
)
STORED BY 'org.elasticsearch.hadoop.hive.EsStorageHandler'
TBLPROPERTIES('es.resource' = 'cty_test/cty_test', 
'es.nodes'='172.16.98.113,172.16.98.149,172.16.98.150,172.16.98.151,172.16.98.152',
'es.port'='9200',
'es.mapping.names'= 'addTime:addTime',
'es.mapping.date.rich'='false',
  'es.index.auto.create'='false',
)
注意,hive表数据类型要和es一致,除了es的date要转成hive的string,同时要加参数’es.mapping.date.rich’=‘false’,否则查询会报错.

2 通过映射表向其他表insert

参考:

https://www.cnblogs.com/koushr/p/9505435.html