1、下载相应的jar包
2、
2、添加jar配置
HIVE_AUX_JARS_PATH=/usr/share/hive
3、建表语句
1、Elecsearch 存在
{
"_index": "es_hive_test",
"_type": "doc",
"_id": "w",
"_score": 1,
"_source": {
"id": "23",
"area": "hangzhou",
"name": "lisi5"
}
}
CREATE EXTERNAL TABLE tmp_test.es_hive_test2 (
cookieid string ,
id string,
area string,
name string
)
STORED BY 'org.elasticsearch.hadoop.hive.EsStorageHandler'
TBLPROPERTIES('es.nodes' = '10.15.1.41:9200,10.15.1.41:9201,10.15.1.42:9200,10.15.1.42:9201,10.15.1.43:9200,10.15.1.43:9201',
'es.index.auto.create' = 'flase',
'es.resource' = 'es_hive_test/doc',
'es.read.metadata' = 'true',
'es.index.read.missing.as.empty'='true', --防止查询为空值报错
'es.net.http.auth.user'='***',
'es.net.http.auth.pass'='***',
'es.mapping.names' = 'cookieid:_metadata._id,
id:id,
area:area,
name:name'
);
2、Elecsearch 不存在
CREATE EXTERNAL TABLE tmp_test.es_hive_test (
cookieid string ,
id string,
area string,
name string
)
STORED BY 'org.elasticsearch.hadoop.hive.EsStorageHandler'
TBLPROPERTIES('es.nodes' = '10.15.1.41:9200,10.15.1.41:9201,10.15.1.42:9200,10.15.1.42:9201,10.15.1.43:9200,10.15.1.43:9201',
'es.index.auto.create' = 'true',
'es.resource' = 'es_hive_test/doc',
'es.read.metadata' = 'true',
'es.mapping.id'='cookieid' ,
'es.net.http.auth.user'='***',
'es.index.read.missing.as.empty'='true', --防止查询为空值报错
'es.net.http.auth.pass'='***'
'es.mapping.names' = '
id:id,
area:area,
name:name'
);
相关参数:
如果是往_id中插入数据,需要设置’es.mapping.id’ = ‘cookieid’参数,表示Hive中的cookieid字段对应到ES中的_id,而es.mapping.names中不需要再映射,这点和读取时候的配置不一样