elasticsearch bulk 批量加载索引的实例
来源:互联网 发布:java获取map中的泛型 编辑:程序博客网 时间:2024/06/07 03:08
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.net.InetAddress;
import java.net.UnknownHostException;
import org.elasticsearch.action.bulk.BulkRequestBuilder;
import org.elasticsearch.client.transport.TransportClient;
import org.elasticsearch.common.settings.Settings;
import org.elasticsearch.common.transport.InetSocketTransportAddress;
import org.elasticsearch.transport.client.PreBuiltTransportClient;
public class ElasticSearchBulkIn {
//java -jar shuzilmJob-1.0-SNAPSHOT-jar-with-dependencies.jar ElasticSearchBulkInpublic static void main(String[] args) { try { Settings setting = Settings.builder().put("cluster.name", "du-es").build(); TransportClient client = new PreBuiltTransportClient(setting) .addTransportAddress(new InetSocketTransportAddress(InetAddress.getByName("du-es-1"), 9311)); //Add transport addresses and do something with the client... File article = new File("/home/srvadmin/lw/data/bulk.txt"); FileReader fr = new FileReader(article); BufferedReader bfr = new BufferedReader(fr); String line = null; BulkRequestBuilder bulkRequest = client.prepareBulk(); int count = 0; while ((line = bfr.readLine()) != null) { bulkRequest.add(client.prepareIndex("cell_geo_index", "bds_cell_geo_m").setSource(line)); count++; if (count % 100 == 0) { bulkRequest.execute().actionGet(); bulkRequest.request().requests().clear(); System.out.println(count); } } bulkRequest.execute().actionGet(); bfr.close(); fr.close(); client.close(); } catch (UnknownHostException e) { e.printStackTrace(); } catch (FileNotFoundException e) { e.printStackTrace(); } catch (IOException e) { e.printStackTrace(); }}
}
索引的创建:
curl -XPUT ip:9211/cell_geo_index -d ‘{
“settings”: {
“number_of_shards” : 10,
“number_of_replicas” : 0
},
“mappings” : {
“bds_cell_geo_m” : {
“dynamic” : true,
“properties” : {
“cell_id” : {
“type” : “string”,
“index”: “not_analyzed”
},
“lac_id”:{
“type” : “string”,
“index”: “not_analyzed”
},
“opt_id” : {
“type” : “string”,
“index”: “not_analyzed”
},
“lng_center” : {
“type” : “string”,
“index”: “not_analyzed”
},
“lat_center” : {
“type” : “string”,
“index”: “not_analyzed”
}
}
}
}
}’
加载的文件bulk.txt具体内容如下:
{“cell_id”:”20833037”,”lac_id”:”4394”,”opt_id”:”46000”,”lng_center”:”116.573174”,”lat_center”:”39.861816”}
{“cell_id”:”3449199”,”lac_id”:”4134”,”opt_id”:”46000”,”lng_center”:”116.418603”,”lat_center”:”40.068716”}
- elasticsearch bulk 批量加载索引的实例
- Elasticsearch java api(五) Bulk批量索引
- Elasticsearch java api(五) Bulk批量索引
- Elasticsearch java api(五) Bulk批量索引
- Elasticsearch java api中Bulk批量索引
- Elasticsearch java api(五) Bulk批量索引
- elasticSearch批量操作bulk
- elasticsearch之批量提交Bulk
- Elasticsearch bulk批量增删改
- bulk批量建立索引python
- elasticsearch 批量入库bulk性能测试
- ElasticSearch批量更新索引的优化
- Elasticsearch的Bulk API使用
- Elasticsearch Java API 的使用(9)—Bulk大数据量的批量上传
- Elasticsearch Bulk
- 分布式搜索引擎elasticsearch PHP API index bulk 批量插入操作
- elasticsearch批量index,update,delete——Bulk Helpers
- ElasticSearch实战 (二)CRUD以及bulk批量操作 api
- JZOJ 100023 【NOIP2016提高A组模拟7.6】塔
- 程序员“错误日志”之break、continue、return
- 2016年湖南省第十二届大学生计算机程序设计竞赛(重现)
- 2017.7.5 模拟赛
- C++ cant appear in a constant-expression bug修复
- elasticsearch bulk 批量加载索引的实例
- 2018秋招-阿里内推编程题
- 文章标题
- scanf()是怎么接受数据的
- CatLib新手入门---基础调用流程
- python 统计函数时间 decorator
- 51nod1705 七星剑
- 屏幕的了解,为学习LCD做铺垫
- 如何使用Android Studio阅读开源代码