本文整理汇总了Java中org.elasticsearch.action.bulk.BulkResponse.getItems方法的典型用法代码示例。如果您正苦于以下问题:Java BulkResponse.getItems方法的具体用法?Java BulkResponse.getItems怎么用?Java BulkResponse.getItems使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.elasticsearch.action.bulk.BulkResponse
的用法示例。
在下文中一共展示了BulkResponse.getItems方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: batchDelete
import org.elasticsearch.action.bulk.BulkResponse; //导入方法依赖的package包/类
/**
* 批量删除
*
* @param transportClient
*/
private static void batchDelete(TransportClient transportClient) throws IOException {
BulkRequestBuilder bulkRequestBuilder = transportClient.prepareBulk();
DeleteRequestBuilder deleteRequestBuilder1 = transportClient.prepareDelete("product_index", "product", "1");
DeleteRequestBuilder deleteRequestBuilder2 = transportClient.prepareDelete("product_index", "product", "2");
DeleteRequestBuilder deleteRequestBuilder3 = transportClient.prepareDelete("product_index", "product", "3");
bulkRequestBuilder.add(deleteRequestBuilder1);
bulkRequestBuilder.add(deleteRequestBuilder2);
bulkRequestBuilder.add(deleteRequestBuilder3);
BulkResponse bulkResponse = bulkRequestBuilder.get();
for (BulkItemResponse bulkItemResponse : bulkResponse.getItems()) {
logger.info("--------------------------------version= " + bulkItemResponse.getVersion());
}
}
示例2: batchUpdate
import org.elasticsearch.action.bulk.BulkResponse; //导入方法依赖的package包/类
/**
* 批量更新
*
* @param transportClient
*/
private static void batchUpdate(TransportClient transportClient) throws IOException {
BulkRequestBuilder bulkRequestBuilder = transportClient.prepareBulk();
UpdateRequestBuilder updateRequestBuilder1 = transportClient.prepareUpdate("product_index", "product", "1")
.setDoc(XContentFactory.jsonBuilder()
.startObject()
.field("product_name", "更新后的商品名称1")
.endObject());
UpdateRequestBuilder updateRequestBuilder2 = transportClient.prepareUpdate("product_index", "product", "2")
.setDoc(XContentFactory.jsonBuilder()
.startObject()
.field("product_name", "更新后的商品名称2")
.endObject());
UpdateRequestBuilder updateRequestBuilder3 = transportClient.prepareUpdate("product_index", "product", "3")
.setDoc(XContentFactory.jsonBuilder()
.startObject()
.field("product_name", "更新后的商品名称3")
.endObject());
bulkRequestBuilder.add(updateRequestBuilder1);
bulkRequestBuilder.add(updateRequestBuilder2);
bulkRequestBuilder.add(updateRequestBuilder3);
BulkResponse bulkResponse = bulkRequestBuilder.get();
for (BulkItemResponse bulkItemResponse : bulkResponse.getItems()) {
logger.info("--------------------------------version= " + bulkItemResponse.getVersion());
}
}
示例3: deleteES
import org.elasticsearch.action.bulk.BulkResponse; //导入方法依赖的package包/类
private static void deleteES(Client client) {
BulkRequestBuilder bulkRequest = client.prepareBulk();
SearchResponse response = client.prepareSearch(index).setTypes(type)
.setSearchType(SearchType.DFS_QUERY_THEN_FETCH)
.setQuery(QueryBuilders.matchAllQuery())
.setFrom(0).setSize(20).setExplain(true).execute().actionGet();
System.out.println("length: " + response.getHits().getHits().length);
if (response.getHits().getHits().length != 0) {
for (SearchHit hit : response.getHits()) {
String id = hit.getId();
System.out.println("id: " + id);
bulkRequest.add(client.prepareDelete(index, type, id).request());
}
BulkResponse bulkResponse = bulkRequest.get();
if (bulkResponse.hasFailures()) {
for (BulkItemResponse item : bulkResponse.getItems()) {
System.out.println(item.getFailureMessage());
}
} else {
System.out.println("delete ok");
}
} else {
System.out.println("delete ok");
}
}
示例4: insert
import org.elasticsearch.action.bulk.BulkResponse; //导入方法依赖的package包/类
@Override
public void insert(List<BucketOwner> bucketOwners, Date collectionTime) {
if (bucketOwners != null && !bucketOwners.isEmpty()) {
BulkRequestBuilder requestBuilder = elasticClient.prepareBulk();
// Generate JSON for object buckets info
for (BucketOwner bucketOwner : bucketOwners) {
XContentBuilder objectBucketBuilder = toJsonFormat(bucketOwner, collectionTime);
IndexRequestBuilder request = elasticClient.prepareIndex().setIndex(bucketownerIndexDayName)
.setType(BUCKET_OWNER_INDEX_TYPE).setSource(objectBucketBuilder);
requestBuilder.add(request);
}
BulkResponse bulkResponse = requestBuilder.execute().actionGet();
int items = bulkResponse.getItems().length;
LOGGER.info("Took " + bulkResponse.getTookInMillis() + " ms to index [" + items + "] items in ElasticSearch"
+ "index: " + bucketownerIndexDayName + " index type: " + BUCKET_OWNER_INDEX_TYPE);
if (bulkResponse.hasFailures()) {
LOGGER.error("Failures occured while items in ElasticSearch " + "index: " + bucketownerIndexDayName
+ " index type: " + BUCKET_OWNER_INDEX_TYPE);
}
}
}
示例5: deleteAllIds
import org.elasticsearch.action.bulk.BulkResponse; //导入方法依赖的package包/类
@Override
public List<String> deleteAllIds(final Collection<String> ids) {
if (ids.isEmpty()) {
return ImmutableList.of();
}
final BulkRequestBuilder bulk = client
.prepareBulk()
.setRefreshPolicy(policy.get());
for (final String id : ids) {
bulk.add(client.prepareDelete(index, type, id));
}
final BulkResponse response = bulk.execute().actionGet();
final ImmutableList.Builder<String> builder = ImmutableList.builder();
for (final BulkItemResponse item : response.getItems()) {
builder.add(item.getId());
}
return builder.build();
}
示例6: bulkIndex
import org.elasticsearch.action.bulk.BulkResponse; //导入方法依赖的package包/类
/**
* Given that streams are processed in bulks, we're making use of
* the ElasticSearch capability to index bulks of documents. It takes a list
* of ids and a list of texts.
*
* @param tweetIds
* @param tweets
*/
public void bulkIndex(List<Long> tweetIds, List<String> tweets) {
BulkRequestBuilder requestBuilder = client.prepareBulk();
for(int i = 0; i < tweetIds.size(); i++) {
XContentBuilder builder;
try {
builder = jsonBuilder()
.startObject()
.field("text", tweets.get(i))
.field("id", tweetIds.get(i))
.endObject();
} catch (IOException e) {
continue;
}
IndexRequestBuilder request = client.prepareIndex("hackaton", "tweets")
.setIndex("hackaton")
.setType("tweets")
.setSource(builder);
requestBuilder.add(request);
}
BulkResponse bulkResponse = requestBuilder.execute().actionGet();
int items = bulkResponse.getItems().length;
System.err.print("indexed [" + items + "] items, with failures? [" + bulkResponse.hasFailures() + "]");
}
示例7: afterBulk
import org.elasticsearch.action.bulk.BulkResponse; //导入方法依赖的package包/类
@Override
public void afterBulk(long executionId, BulkRequest request,
BulkResponse response) {
bulksInProgress.decrementAndGet();
if (response.hasFailures()) {
for (BulkItemResponse item : response.getItems()) {
if (item.isFailed()) {
counts.failures++;
} else {
counts.successes++;
}
}
} else {
counts.successes += response.getItems().length;
}
checkRelease();
}
示例8: executeESBulkRequest
import org.elasticsearch.action.bulk.BulkResponse; //导入方法依赖的package包/类
@Override
public void executeESBulkRequest(BulkRequestBuilder esBulk) throws ElasticsearchException,
BulkUpdatePartialFailureException {
BulkResponse response = esBulk.execute().actionGet();
if (response.hasFailures()) {
boolean containsSuccess = false;
int numOfFailures = 0;
for (BulkItemResponse bir : response.getItems()) {
if (!bir.isFailed()) {
containsSuccess = true;
} else {
numOfFailures++;
}
}
if (containsSuccess) {
throw new BulkUpdatePartialFailureException(response.buildFailureMessage(), numOfFailures);
} else {
throw new ElasticsearchException("Failed to completely execute ES index bulk update for " + numOfFailures
+ " commands: " + response.buildFailureMessage());
}
}
}
示例9: EsBulkResponseSummary
import org.elasticsearch.action.bulk.BulkResponse; //导入方法依赖的package包/类
public EsBulkResponseSummary(List<BulkResponse> responses) {
for (BulkResponse br : responses) {
for (BulkItemResponse itemResponse : br.getItems()) {
if (itemResponse.isFailed()) {
failed.put(getItemId(itemResponse), itemResponse.getFailureMessage());
} else {
succeeded.put(getItemId(itemResponse), itemResponse.getOpType());
}
}
}
}
示例10: insert
import org.elasticsearch.action.bulk.BulkResponse; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void insert(ListObjectsResult listObjectsResult, String namespace, String bucket, Date collectionTime) {
if( listObjectsResult == null ||
listObjectsResult.getObjects() == null ||
listObjectsResult.getObjects().isEmpty() ) {
// nothing to insert
return;
}
BulkRequestBuilder requestBuilder = elasticClient.prepareBulk();
// Generate JSON for object buckets info
for( S3Object s3Object : listObjectsResult.getObjects() ) {
XContentBuilder s3ObjectBuilder = toJsonFormat(s3Object, namespace, bucket, collectionTime);
IndexRequestBuilder request = elasticClient.prepareIndex()
.setIndex(s3ObjectIndexDayName)
.setType(S3_OBJECT_INDEX_TYPE)
.setSource(s3ObjectBuilder);
requestBuilder.add(request);
}
BulkResponse bulkResponse = requestBuilder.execute().actionGet();
int items = bulkResponse.getItems().length;
LOGGER.info( "Took " + bulkResponse.getTookInMillis() + " ms to index [" + items + "] items in Elasticsearch " + "index: " +
s3ObjectIndexDayName + " index type: " + S3_OBJECT_INDEX_TYPE );
if( bulkResponse.hasFailures() ) {
LOGGER.error( "Failure(s) occured while items in Elasticsearch " + "index: " +
s3ObjectIndexDayName + " index type: " + S3_OBJECT_INDEX_TYPE );
}
}
示例11: insert
import org.elasticsearch.action.bulk.BulkResponse; //导入方法依赖的package包/类
/**
* {@inheritDoc}
*/
@Override
public void insert( ObjectBuckets objectBuckets, Date collectionTime ) {
if( objectBuckets == null ||
objectBuckets.getObjectBucket() == null ||
objectBuckets.getObjectBucket().isEmpty() ) {
// nothing to insert
return;
}
BulkRequestBuilder requestBuilder = elasticClient.prepareBulk();
// Generate JSON for object buckets info
for( ObjectBucket objectBucket : objectBuckets.getObjectBucket() ) {
XContentBuilder objectBucketBuilder = toJsonFormat(objectBucket, collectionTime);
IndexRequestBuilder request = elasticClient.prepareIndex()
.setIndex(objectBucketIndexDayName)
.setType(OBJECT_BUCKET_INDEX_TYPE)
.setSource(objectBucketBuilder);
requestBuilder.add(request);
}
BulkResponse bulkResponse = requestBuilder.execute().actionGet();
int items = bulkResponse.getItems().length;
LOGGER.info( "Took " + bulkResponse.getTookInMillis() + " ms to index [" + items + "] items in ElasticSearch" + "index: " +
objectBucketIndexDayName + " index type: " + OBJECT_BUCKET_INDEX_TYPE );
if( bulkResponse.hasFailures() ) {
LOGGER.error( "Failures occured while items in ElasticSearch " + "index: " +
objectBucketIndexDayName + " index type: " + OBJECT_BUCKET_INDEX_TYPE );
}
}
示例12: insert
import org.elasticsearch.action.bulk.BulkResponse; //导入方法依赖的package包/类
@Override
public void insert(VdcDetails vdcDetails, Date collectionTime) {
if (vdcDetails == null || vdcDetails.getVdcDetails() == null || vdcDetails.getVdcDetails().isEmpty()) {
return;
}
BulkRequestBuilder requestBuilder = elasticClient.prepareBulk();
// Generate JSON for object buckets info
for( VdcDetail vdcDetail : vdcDetails.getVdcDetails() ) {
XContentBuilder objectBucketBuilder = toJsonFormat(vdcDetail, collectionTime);
IndexRequestBuilder request = elasticClient.prepareIndex()
.setIndex(vdcIndexDayName)
.setType(VDC_INDEX_TYPE)
.setSource(objectBucketBuilder);
requestBuilder.add(request);
}
BulkResponse bulkResponse = requestBuilder.execute().actionGet();
int items = bulkResponse.getItems().length;
LOGGER.info( "Took " + bulkResponse.getTookInMillis() + " ms to index [" + items + "] items in ElasticSearch" + "index: " +
vdcIndexDayName + " index type: " + VDC_INDEX_TYPE );
if( bulkResponse.hasFailures() ) {
LOGGER.error( "Failures occured while items in ElasticSearch " + "index: " +
vdcIndexDayName + " index type: " + VDC_INDEX_TYPE );
}
}
示例13: afterBulk
import org.elasticsearch.action.bulk.BulkResponse; //导入方法依赖的package包/类
@Override
public void afterBulk(long executionId, BulkRequest request, BulkResponse response) {
if (response.hasFailures()) {
BulkItemResponse itemResponse;
Throwable failure;
RestStatus restStatus;
try {
for (int i = 0; i < response.getItems().length; i++) {
itemResponse = response.getItems()[i];
failure = callBridge.extractFailureCauseFromBulkItemResponse(itemResponse);
if (failure != null) {
LOG.error("Failed Elasticsearch item request: {}", itemResponse.getFailureMessage(), failure);
restStatus = itemResponse.getFailure().getStatus();
if (restStatus == null) {
failureHandler.onFailure(request.requests().get(i), failure, -1, requestIndexer);
} else {
failureHandler.onFailure(request.requests().get(i), failure, restStatus.getStatus(), requestIndexer);
}
}
}
} catch (Throwable t) {
// fail the sink and skip the rest of the items
// if the failure handler decides to throw an exception
failureThrowable.compareAndSet(null, t);
}
}
if (flushOnCheckpoint) {
numPendingRequests.getAndAdd(-request.numberOfActions());
}
}
示例14: executeBulkRequest
import org.elasticsearch.action.bulk.BulkResponse; //导入方法依赖的package包/类
protected void executeBulkRequest(BulkRequestBuilder bulkRequest) {
BulkResponse bulkResponse = bulkRequest.execute().actionGet();
getLog().info("Bulk request of batch size: " + bulkRequest.numberOfActions() + " took "
+ bulkResponse.getTookInMillis() + " ms in index builder: " + getName());
for (BulkItemResponse response : bulkResponse.getItems()) {
if (response.getResponse() instanceof DeleteResponse) {
DeleteResponse deleteResponse = response.getResponse();
if (response.isFailed()) {
getLog().error("Problem deleting doc: " + response.getId() + " in index builder: " + getName()
+ " error: " + response.getFailureMessage());
} else if (!deleteResponse.isFound()) {
getLog().debug("ES could not find a doc with id: " + deleteResponse.getId()
+ " to delete in index builder: " + getName());
} else {
getLog().debug("ES deleted a doc with id: " + deleteResponse.getId() + " in index builder: "
+ getName());
}
} else if (response.getResponse() instanceof IndexResponse) {
IndexResponse indexResponse = response.getResponse();
if (response.isFailed()) {
getLog().error("Problem updating content for doc: " + response.getId() + " in index builder: "
+ getName() + " error: " + response.getFailureMessage());
} else {
getLog().debug("ES indexed content for doc with id: " + indexResponse.getId()
+ " in index builder: " + getName());
}
}
}
}
示例15: bulkUpdateIndexes
import org.elasticsearch.action.bulk.BulkResponse; //导入方法依赖的package包/类
protected void bulkUpdateIndexes( ) {
List<Tuple> inputs = new ArrayList<>(queue.size());
queue.drainTo(inputs);
BulkRequestBuilder bulkRequest = client.prepareBulk();
for (Tuple input : inputs) {
Document<T> doc = mapper.map(input);
IndexRequestBuilder request = client.prepareIndex(doc.getName(), doc.getType(), doc.getId()).setSource((String)doc.getSource());
if(doc.getParentId() != null) {
request.setParent(doc.getParentId());
}
bulkRequest.add(request);
}
try {
if (bulkRequest.numberOfActions() > 0) {
BulkResponse bulkItemResponses = bulkRequest.execute().actionGet();
if (bulkItemResponses.hasFailures()) {
BulkItemResponse[] items = bulkItemResponses.getItems();
for (int i = 0; i < items.length; i++) {
ackOrFail(items[i], inputs.get(i));
}
} else {
ackAll(inputs);
}
}
} catch (ElasticsearchException e) {
LOGGER.error("Unable to process bulk request, " + inputs.size() + " tuples are in failure", e);
outputCollector.reportError(e.getRootCause());
failAll(inputs);
}
}