对于es批量上传数据的阶段总结


        String json = "{" +
                "\"user\":\"kimchy\"," +
                "\"postDate\":\"2013-01-30\"," +
                "\"message\":\"trying out Elasticsearch\"" +
                "}";
        //2
        Map<String,Object> json2 =  new HashMap<String,Object>();
        json2.put( "user" , "kimchy" );
        json2.put( "postDate" , new Date());
        json2.put( "message" , "trying出Elasticsearch");
        //发送1
        IndexResponse response = client2.prepareIndex("twitter","tweet").setSource(json).get();
        long time=System.currentTimeMillis();
        for(int i =0;i<11000;i++){
            client2.prepareIndex("twitter","tweet").setSource(json).get();
        }
        System.out.println(System.currentTimeMillis()-time);
        time=System.currentTimeMillis();

        for(int i =0;i<11000;i++){
            client2.prepareIndex("twitter","tweet").setSource(json).get();
        }

System.out.println(System.currentTimeMillis()-time);

 BulkRequestBuilder bulkRequestBuilder=client2.prepareBulk();
        long time=System.currentTimeMillis();
        for(int i =0;i<11000;i++){
//            client2.prepareIndex("twitter","tweet").setSource(json).get();
            bulkRequestBuilder.add(client2.prepareIndex("twitter","tweet").setSource(json));
        }
        System.out.println(System.currentTimeMillis()-time);
        time=System.currentTimeMillis();
        for(int i =0;i<11000;i++){
//            client2.prepareIndex("twitter","tweet").setSource(json).get();
            bulkRequestBuilder.add(client2.prepareIndex("twitter","tweet").setSource(json2));

        }
        System.out.println(System.currentTimeMillis()-time);




上传Json格式和Map格式的数据效率基本一致。

如果通过批处理操作会快很多很多,11000条数据,单条上传要一分钟,批处理只需要几秒。

我这次的任务:从txt中读取1500W行500列数据,存到es中。

在没有采用多线程的情况下,7~8s能上传1500行数据。


正在尝试多线程,会持续更新。

  • 1
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值