當前位置: 首頁>>代碼示例>>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;未經允許,請勿轉載。