1. 将两个jar包添加到Hive的 hive.aux.jars.path目录
org.elasticsearch
elasticsearch-hadoop
6.6.2
commons-httpclient
commons-httpclient
3.1
在hive中创建es索引的外联表
create external table charge_current_frequency_es
(
province string,
vehicleType string,
vin string,
chargeType string,
chargeCurrentFrequency array,
statis_time string
) STORED BY 'org.elasticsearch.hadoop.hive.EsStorageHandler'
location '/warningplatform.db/ads/charge_current_frequency_es'
TBLPROPERTIES ('es.resource' = 'charge_current_frequency/charge_current_frequency',
'es.mapping.names' =
'province:province,vehicleType:vehicleType,vin:vin,chargeType:chargeType,chargeCurrentFrequency:chargeCurrentFrequency,statis_time:time',
'es.nodes' = '192.168.11.29',
'es.port' = '9200'
);
指定hive与es字段的匹配规则
hive中的string可以写入es的date类型,格式可以是yyyy-MM-dd HH:mm:ss,但是hive读取es数据的时候,不能以string类型去接收es中date类型且格式为yyyy-MM-dd HH:mm:ss的字段。
对hive的插入和查询,即为对es索引的插入和查询。
3. 类型匹配