Hive与es数据的导入和导出

1. 将两个jar包添加到Hive的 hive.aux.jars.path目录

<dependency>
	<groupId>org.elasticsearch</groupId>
	<artifactId>elasticsearch-hadoop</artifactId>
	<version>6.6.2</version>
</dependency>
<dependency>
	<groupId>commons-httpclient</groupId>
	<artifactId>commons-httpclient</artifactId>
	<version>3.1</version>
</dependency>

在hive中建立es索引的外联表

create external table charge_current_frequency_es
(
    province               string,
    vehicleType            string,
    vin                    string,
    chargeType             string,
    chargeCurrentFrequency array<bigint>,
    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. 类型匹配

相关文章
相关标签/搜索