当前位置: 首页>>代码示例>>Java>>正文


Java BulkResponse.iterator方法代码示例

本文整理汇总了Java中org.elasticsearch.action.bulk.BulkResponse.iterator方法的典型用法代码示例。如果您正苦于以下问题:Java BulkResponse.iterator方法的具体用法?Java BulkResponse.iterator怎么用?Java BulkResponse.iterator使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.elasticsearch.action.bulk.BulkResponse的用法示例。


在下文中一共展示了BulkResponse.iterator方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: writeToNoSQL

import org.elasticsearch.action.bulk.BulkResponse; //导入方法依赖的package包/类
@Override
public void writeToNoSQL(List<Map<String, Object>> entityList) {
	JSONArray array = JSONArray.fromObject(entityList);
	for (int i = 0; i < array.size(); i++) {
		IndexRequestBuilder builder = client.prepareIndex(index_name, index_type);
		if (getPrimaryKey() != null)
			builder.setId( ((JSONObject)array.get(i)).getString(getPrimaryKey()));
		builder.setSource(array.get(i).toString());
		bulkRequest.add(builder);
	}
	if (bulkRequest.numberOfActions() > 0) {
		long  t1 = System.currentTimeMillis();
		ListenableActionFuture<BulkResponse>  action = bulkRequest.execute();
		long t2 = System.currentTimeMillis();
		BulkResponse response = action.actionGet();
	    for (Iterator<BulkItemResponse> iterator = response.iterator(); iterator.hasNext();) {
	      BulkItemResponse e = (BulkItemResponse) iterator.next();
	      if (e.isFailed()) 
	        throw new FailedCommunicationException("Insertion to ES failed.");
	    }
		log.info("Time taken to Write "+ bulkRequest.numberOfActions() + " documents to ES :" + ((t2-t1))  + " ms");
	}
}
 
开发者ID:msathis,项目名称:SQLToNoSQLImporter,代码行数:24,代码来源:ESWriter.java

示例2: afterBulk

import org.elasticsearch.action.bulk.BulkResponse; //导入方法依赖的package包/类
@Override
public void afterBulk(long executionId, BulkRequest request,
        BulkResponse response) {
    logger.debug("afterBulk {} failures:{}", executionId,
            response.hasFailures());
    if (response.hasFailures()) {
        long succeeded = 0;
        for (Iterator<BulkItemResponse> i = response.iterator(); i
                .hasNext(); ) {
            if (!i.next().isFailed()) {
                succeeded++;
            }
        }
        if (succeeded > 0) {
            succeededDocs.addAndGet(succeeded);
        }
    } else {
        succeededDocs.addAndGet(request.numberOfActions());
    }
    bulkProcessed();
}
 
开发者ID:crate,项目名称:elasticsearch-inout-plugin,代码行数:22,代码来源:BulkWriterCollector.java

示例3: buildWriteReponse

import org.elasticsearch.action.bulk.BulkResponse; //导入方法依赖的package包/类
protected BulkWriterResponse buildWriteReponse(Iterable<Tuple> tuples, BulkResponse bulkResponse) throws Exception {
  // Elasticsearch responses are in the same order as the request, giving us an implicit mapping with Tuples
  BulkWriterResponse writerResponse = new BulkWriterResponse();
  if (bulkResponse.hasFailures()) {
    Iterator<BulkItemResponse> respIter = bulkResponse.iterator();
    Iterator<Tuple> tupleIter = tuples.iterator();
    while (respIter.hasNext() && tupleIter.hasNext()) {
      BulkItemResponse item = respIter.next();
      Tuple tuple = tupleIter.next();

      if (item.isFailed()) {
        writerResponse.addError(item.getFailure().getCause(), tuple);
      } else {
        writerResponse.addSuccess(tuple);
      }

      // Should never happen, so fail the entire batch if it does.
      if (respIter.hasNext() != tupleIter.hasNext()) {
        throw new Exception(bulkResponse.buildFailureMessage());
      }
    }
  } else {
    writerResponse.addAllSuccesses(tuples);
  }

  return writerResponse;
}
 
开发者ID:apache,项目名称:metron,代码行数:28,代码来源:ElasticsearchWriter.java

示例4: writeToNoSQL

import org.elasticsearch.action.bulk.BulkResponse; //导入方法依赖的package包/类
@Override
public void writeToNoSQL(List<Map<String, Object>> entityList) {

    BulkRequestBuilder bulkRequest = client.prepareBulk();

    JSONArray array = JSONArray.fromObject(entityList);
    for (int i = 0; i < array.size(); i++) {
        IndexRequestBuilder builder = client.prepareIndex(index_name, index_type);
        if (getPrimaryKey() != null) {
            builder.setId(((JSONObject) array.get(i)).getString(getPrimaryKey()));
        }
        builder.setSource(array.get(i).toString());
        bulkRequest.add(builder);
    }
    if (bulkRequest.numberOfActions() > 0) {
        long t1 = System.currentTimeMillis();
        ListenableActionFuture<BulkResponse> action = bulkRequest.execute();
        long t2 = System.currentTimeMillis();
        BulkResponse response = action.actionGet();
        for (Iterator<BulkItemResponse> iterator = response.iterator(); iterator.hasNext();) {
            BulkItemResponse e = (BulkItemResponse) iterator.next();
            if (e.isFailed()) {
                throw new FailedCommunicationException("Insertion to ES failed.");
            }
        }
        log.info("Time taken to Write " + bulkRequest.numberOfActions() + " documents to ES :" + ((t2 - t1)) + " ms");
    }
}
 
开发者ID:bench,项目名称:Sql2NoSql-Importer,代码行数:29,代码来源:ESWriter.java

示例5: afterBulk

import org.elasticsearch.action.bulk.BulkResponse; //导入方法依赖的package包/类
@Override
public void afterBulk(long executionId, BulkRequest request,
        BulkResponse response) {
    LOG.debug("afterBulk [{}] with {} responses", executionId,
            request.numberOfActions());
    long msec = response.getTookInMillis();
    eventCounter.scope("bulks_received").incrBy(1);
    eventCounter.scope("bulk_msec").incrBy(msec);
    Iterator<BulkItemResponse> bulkitemiterator = response.iterator();
    int itemcount = 0;
    int acked = 0;
    synchronized (waitAck) {
        while (bulkitemiterator.hasNext()) {
            BulkItemResponse bir = bulkitemiterator.next();
            itemcount++;
            String id = bir.getId();
            List<Tuple> xx = waitAck.getIfPresent(id);
            if (xx != null) {
                LOG.debug("Acked {} tuple(s) for ID {}", xx.size(), id);
                for (Tuple x : xx) {
                    acked++;
                    // ack and put in cache
                    super.ack(x, x.getStringByField("url"));
                }
                waitAck.invalidate(id);
            } else {
                LOG.warn("Could not find unacked tuple for {}", id);
            }
        }

        LOG.info("Bulk response [{}] : items {}, waitAck {}, acked {}",
                executionId, itemcount, waitAck.size(), acked);
        if (waitAck.size() > 0 && LOG.isDebugEnabled()) {
            for (String kinaw : waitAck.asMap().keySet()) {
                LOG.debug(
                        "Still in wait ack after bulk response [{}] => {}",
                        executionId, kinaw);
            }
        }
    }
}
 
开发者ID:eorliac,项目名称:patent-crawler,代码行数:42,代码来源:StatusUpdaterBolt.java

示例6: afterBulk

import org.elasticsearch.action.bulk.BulkResponse; //导入方法依赖的package包/类
@Override
public void afterBulk(long executionId, BulkRequest request,
        BulkResponse response) {
    LOG.debug("afterBulk [{}] with {} responses", executionId,
            request.numberOfActions());
    long msec = response.getTook().getMillis();
    eventCounter.scope("bulks_received").incrBy(1);
    eventCounter.scope("bulk_msec").incrBy(msec);
    Iterator<BulkItemResponse> bulkitemiterator = response.iterator();
    int itemcount = 0;
    int acked = 0;
    synchronized (waitAck) {
        while (bulkitemiterator.hasNext()) {
            BulkItemResponse bir = bulkitemiterator.next();
            itemcount++;
            String id = bir.getId();
            List<Tuple> xx = waitAck.getIfPresent(id);
            if (xx != null) {
                LOG.debug("Acked {} tuple(s) for ID {}", xx.size(), id);
                for (Tuple x : xx) {
                    acked++;
                    // ack and put in cache
                    super.ack(x, x.getStringByField("url"));
                }
                waitAck.invalidate(id);
            } else {
                LOG.warn("Could not find unacked tuple for {}", id);
            }
        }

        LOG.info("Bulk response [{}] : items {}, waitAck {}, acked {}",
                executionId, itemcount, waitAck.size(), acked);
        if (waitAck.size() > 0 && LOG.isDebugEnabled()) {
            for (String kinaw : waitAck.asMap().keySet()) {
                LOG.debug(
                        "Still in wait ack after bulk response [{}] => {}",
                        executionId, kinaw);
            }
        }
    }
}
 
开发者ID:DigitalPebble,项目名称:storm-crawler,代码行数:42,代码来源:StatusUpdaterBolt.java


注:本文中的org.elasticsearch.action.bulk.BulkResponse.iterator方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。