做接口性能測試前,經常需要往ES中造數。
記錄一下,舉個栗子:
1.在hive中創建數據表並造數,如edw.courier_order_time。可以通過其它表創建新表(create table tablename as select )
2.建立hive與es的映射關係
drop table edw.courier_work_time_total_20190812 ;
CREATE EXTERNAL TABLE edw.courier_work_time_total_20190812 (
courierId bigint COMMENT '閃送員id',
workTime bigint COMMENT '工作時長',
workServiceTime bigint COMMENT '休息時長',
day string COMMENT '日期'
)
STORED BY 'org.elasticsearch.hadoop.hive.EsStorageHandler'
TBLPROPERTIES(
'es.nodes' = '192.1.1.1:9200,192.1.1.2:9200,192.1.1.3:9200,192.1.1.4:9200',
'es.index.auto.create' = 'true',
'es.nodes.wan.only'='true',
'es.number_of_shards'='1',
'es.resource' = 'courier_work_time_total_20190812/courier_work_time',--對應es中的index/type
'es.mapping.names' = '' --一般都是一一映射
);
3.插入數據到映射表裏
insert overwrite table edw.courier_work_time_total_20190812
select * from edw.courier_order_time where dt_ymd = 20190812;
4.查看數據是否正確插入到es
查看mapping(ps:可以在步驟1之前建立好mapping):
curl -X GET 'http://bigdata-dev-es-1:9200/courier_work_time_total_20190812/_mapping/courier_work_time?pretty'
查看數據量:
curl 'http://bigdata-dev-es-1:9200/courier_work_time_total_20190812/courier_work_time/_count?pretty'
另外:
建索引語句:
curl -H "Content-Type: application/json" -XPUT 'http://bigdata-dev-es-1:9200/gal_dw?pretty=true' -d '{"mappings":{"dwv_tkt_ride":{"properties":{"activity_id":{"type":"integer"},"bi_type":{"type":"keyword"},"channel_id":{"type":"integer"}}}}}'
刪除索引語句:
curl -XDELETE 'http://bigdata-dev-es-1:9200/gal_dw/'