本文整理汇总了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");
}
}
示例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();
}
示例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;
}
示例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");
}
}
示例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);
}
}
}
}
示例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);
}
}
}
}