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


Java BulkItemResponse类代码示例

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


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

示例1: batchDelete

import org.elasticsearch.action.bulk.BulkItemResponse; //导入依赖的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());
	}

}
 
开发者ID:judasn,项目名称:Elasticsearch-Tutorial-zh-CN,代码行数:23,代码来源:BaseDemo.java

示例2: createIndex

import org.elasticsearch.action.bulk.BulkItemResponse; //导入依赖的package包/类
/**
 * 创建索引
 *
 * @param datas
 * @param indexType
 */
public static <T extends IdAble> void createIndex(List<T> datas, IndexType indexType) {
    // 批量处理request
    BulkRequestBuilder bulkRequest = EsClientManager.getClient().prepareBulk();
    byte[] json;
    for (T t : datas) {
        json = EsDataUtil.toBytes(t);
        bulkRequest.add(new IndexRequest(esprop.getIndice(), indexType.getDataName(), t.getId() + "").source(json));
    }
    // 执行批量处理request
    BulkResponse bulkResponse = bulkRequest.get();
    // 处理错误信息
    if (bulkResponse.hasFailures()) {
        LOGGER.warn("====================批量创建索引过程中出现错误 下面是错误信息==========================");
        long count = 0L;
        for (BulkItemResponse bulkItemResponse : bulkResponse) {
            LOGGER.warn("类型 " + indexType.getDataName() + " 发生错误的 索引id为 : " + bulkItemResponse.getId() + " ,错误信息为:" + bulkItemResponse.getFailureMessage());
            count++;
        }
        LOGGER.warn("====================批量创建索引过程中出现错误 上面是错误信息 共有: " + count + " 条记录==========================");
    }
}
 
开发者ID:wxz1211,项目名称:dooo,代码行数:28,代码来源:IndexManager.java

示例3: batchUpdate

import org.elasticsearch.action.bulk.BulkItemResponse; //导入依赖的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());
	}
}
 
开发者ID:judasn,项目名称:Elasticsearch-Tutorial-zh-CN,代码行数:37,代码来源:BaseDemo.java

示例4: deleteES

import org.elasticsearch.action.bulk.BulkItemResponse; //导入依赖的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");
  }
}
 
开发者ID:MoneZhao,项目名称:elasticsearch,代码行数:26,代码来源:App.java

示例5: deleteAllIds

import org.elasticsearch.action.bulk.BulkItemResponse; //导入依赖的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();
}
 
开发者ID:jloisel,项目名称:elastic-crud,代码行数:23,代码来源:ElasticSearchRepository.java

示例6: getOKCount

import org.elasticsearch.action.bulk.BulkItemResponse; //导入依赖的package包/类
@Override
public int getOKCount()
{
	if (_countOK == null)
	{
		int count = 0;
		for (final BulkItemResponse response : esResponse.getItems())
		{
			if (!response.isFailed())
			{
				count++;
			}
		}

		_countOK = count;
	}
	return _countOK;
}
 
开发者ID:metasfresh,项目名称:metasfresh,代码行数:19,代码来源:ESIndexerResult.java

示例7: getFailuresCount

import org.elasticsearch.action.bulk.BulkItemResponse; //导入依赖的package包/类
@Override
public int getFailuresCount()
{
	if (_countFailures == null)
	{
		int count = 0;
		for (final BulkItemResponse response : esResponse.getItems())
		{
			if (response.isFailed())
			{
				count++;
			}
		}
		
		_countFailures = count;
	}
	return _countFailures;
}
 
开发者ID:metasfresh,项目名称:metasfresh,代码行数:19,代码来源:ESIndexerResult.java

示例8: testSingleFailure

import org.elasticsearch.action.bulk.BulkItemResponse; //导入依赖的package包/类
@Test
public void testSingleFailure() throws Exception {
    Tuple tuple1 = mock(Tuple.class);

    BulkResponse response = mock(BulkResponse.class);
    when(response.hasFailures()).thenReturn(true);

    Exception e = new IllegalStateException();
    BulkItemResponse itemResponse = buildBulkItemFailure(e);
    when(response.iterator()).thenReturn(ImmutableList.of(itemResponse).iterator());

    BulkWriterResponse expected = new BulkWriterResponse();
    expected.addError(e, tuple1);

    ElasticsearchWriter esWriter = new ElasticsearchWriter();
    BulkWriterResponse actual = esWriter.buildWriteReponse(ImmutableList.of(tuple1), response);

    assertEquals("Response should have one error and zero successes", expected, actual);
}
 
开发者ID:apache,项目名称:metron,代码行数:20,代码来源:ElasticsearchWriterTest.java

示例9: testSuccessAndFailure

import org.elasticsearch.action.bulk.BulkItemResponse; //导入依赖的package包/类
@Test
public void testSuccessAndFailure() throws Exception {
    Tuple tuple1 = mock(Tuple.class);
    Tuple tuple2 = mock(Tuple.class);

    BulkResponse response = mock(BulkResponse.class);
    when(response.hasFailures()).thenReturn(true);

    Exception e = new IllegalStateException("Cause");
    BulkItemResponse itemResponse = buildBulkItemFailure(e);

    BulkItemResponse itemResponse2 = mock(BulkItemResponse.class);
    when(itemResponse2.isFailed()).thenReturn(false);

    when(response.iterator()).thenReturn(ImmutableList.of(itemResponse, itemResponse2).iterator());

    BulkWriterResponse expected = new BulkWriterResponse();
    expected.addError(e, tuple1);
    expected.addSuccess(tuple2);

    ElasticsearchWriter esWriter = new ElasticsearchWriter();
    BulkWriterResponse actual = esWriter.buildWriteReponse(ImmutableList.of(tuple1, tuple2), response);

    assertEquals("Response should have one error and one success", expected, actual);
}
 
开发者ID:apache,项目名称:metron,代码行数:26,代码来源:ElasticsearchWriterTest.java

示例10: writeToNoSQL

import org.elasticsearch.action.bulk.BulkItemResponse; //导入依赖的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

示例11: executeBuilder

import org.elasticsearch.action.bulk.BulkItemResponse; //导入依赖的package包/类
void executeBuilder(BulkRequestBuilder bulkRequestBuilder)
{
	if(bulkRequestBuilder.numberOfActions() == 0)
		return;
	
	++stats.flushes;
	BulkResponse response = bulkRequestBuilder.execute().actionGet();
	if (response.hasFailures()) {
              logger.warn("failed to execute" + response.buildFailureMessage());
          }
	
	for(BulkItemResponse resp : response){
		if(resp.isFailed()){
			stats.failed++;
		}else{
			stats.succeeded++;
		}
	}
}
 
开发者ID:endgameinc,项目名称:elasticsearch-river-kafka,代码行数:20,代码来源:KafkaRiver.java

示例12: afterBulk

import org.elasticsearch.action.bulk.BulkItemResponse; //导入依赖的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();
}
 
开发者ID:crate,项目名称:elasticsearch-inout-plugin,代码行数:18,代码来源:ImportBulkListener.java

示例13: afterBulk

import org.elasticsearch.action.bulk.BulkItemResponse; //导入依赖的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

示例14: executeBlocking

import org.elasticsearch.action.bulk.BulkItemResponse; //导入依赖的package包/类
private void executeBlocking(final ActionRequest action) {
    try {
        if (action instanceof PutMappingRequest) {
            getDataContext().getElasticSearchClient().createMapping((PutMappingRequest) action);
        } else {
            final ActionResponse result = getDataContext().getElasticSearchClient().execute(action);

            if (result instanceof BulkResponse && ((BulkResponse) result).hasFailures()) {
                BulkItemResponse[] failedItems = ((BulkResponse) result).getItems();
                for (int i = 0; i < failedItems.length; i++) {
                    if (failedItems[i].isFailed()) {
                        final BulkItemResponse failedItem = failedItems[i];
                        logger.error("Bulk failed with item no. {} of {}: id={} op={} status={} error={}", i + 1,
                                failedItems.length, failedItem.getId(), failedItem.getOpType(), failedItem.status(),
                                failedItem.getFailureMessage());
                    }
                }
            }
        }
    } catch (IOException e) {
        logger.warn("Could not execute command {} ", action, e);
        throw new MetaModelException("Could not execute " + action, e);
    }
}
 
开发者ID:apache,项目名称:metamodel,代码行数:25,代码来源:ElasticSearchRestUpdateCallback.java

示例15: executeESBulkRequest

import org.elasticsearch.action.bulk.BulkItemResponse; //导入依赖的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());
		}
	}
}
 
开发者ID:searchisko,项目名称:elasticsearch-river-remote,代码行数:23,代码来源:RemoteRiver.java


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