當前位置: 首頁>>代碼示例>>Java>>正文


Java BulkResponse.hasFailures方法代碼示例

本文整理匯總了Java中org.elasticsearch.action.bulk.BulkResponse.hasFailures方法的典型用法代碼示例。如果您正苦於以下問題:Java BulkResponse.hasFailures方法的具體用法?Java BulkResponse.hasFailures怎麽用?Java BulkResponse.hasFailures使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.elasticsearch.action.bulk.BulkResponse的用法示例。


在下文中一共展示了BulkResponse.hasFailures方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: insertThreadObjectToES

import org.elasticsearch.action.bulk.BulkResponse; //導入方法依賴的package包/類
/**
 * TODO:線程分析數據的存儲
 * 
 * @param result
 */
private void insertThreadObjectToES(List<JavaThreadObject> result) {

    if (this.log.isDebugEnable()) {
        this.log.debug(this, "ThreadObjectToES is :" + JSONHelper.toString(result));
    }

    BulkRequestBuilder bulkRequest = client.getClient().prepareBulk();

    for (JavaThreadObject item : result) {
        pushDataToBulkRequest(item, bulkRequest);
    }

    BulkResponse bulkResponse = bulkRequest.get();
    if (bulkResponse.hasFailures()) {
        log.err(this, "INSERT ThreadAnalysis Data to ES FAIL: " + bulkResponse.buildFailureMessage());
    }
}
 
開發者ID:uavorg,項目名稱:uavstack,代碼行數:23,代碼來源:ThreadAnalysisCollectDataHandler.java

示例2: batchPersistence

import org.elasticsearch.action.bulk.BulkResponse; //導入方法依賴的package包/類
@Override public void batchPersistence(List<?> batchCollection) {
    BulkRequestBuilder bulkRequest = getClient().prepareBulk();

    logger.debug("bulk data size: {}", batchCollection.size());
    if (CollectionUtils.isNotEmpty(batchCollection)) {
        batchCollection.forEach(builder -> {
            if (builder instanceof IndexRequestBuilder) {
                bulkRequest.add((IndexRequestBuilder)builder);
            }
            if (builder instanceof UpdateRequestBuilder) {
                bulkRequest.add((UpdateRequestBuilder)builder);
            }
        });

        BulkResponse bulkResponse = bulkRequest.execute().actionGet();
        if (bulkResponse.hasFailures()) {
            logger.error(bulkResponse.buildFailureMessage());
        }
    }
}
 
開發者ID:apache,項目名稱:incubator-skywalking,代碼行數:21,代碼來源:BatchEsDAO.java

示例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");
  }
}
 
開發者ID:MoneZhao,項目名稱:elasticsearch,代碼行數:26,代碼來源:App.java

示例4: createIndex

import org.elasticsearch.action.bulk.BulkResponse; //導入方法依賴的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

示例5: bulkUpdate

import org.elasticsearch.action.bulk.BulkResponse; //導入方法依賴的package包/類
public static void bulkUpdate(Client client ) throws IOException, InterruptedException, ExecutionException {
	
	BulkRequestBuilder req = client.prepareBulk();
	req.add(client.prepareIndex("search_test","article","2")
				.setSource(jsonBuilder()
						.startObject()
						.field("title","bulk title 02 04-05")));
	req.add(client.prepareIndex("search_test","article","3")
			.setSource(jsonBuilder()
					.startObject()
					.field("title","bulk title 03 04-05")));
	req.add(client.prepareIndex("search_test","article","4")
			.setSource(jsonBuilder()
					.startObject()
					.field("title","bulk title 04 04-05")));
       BulkResponse res = req.execute().actionGet();		
       
       if (res.hasFailures()){
       	System.out.println("Error");
       } else {
       	System.out.println("Done");
       }
       
	
	client.close();
}
 
開發者ID:walle-liao,項目名稱:jaf-examples,代碼行數:27,代碼來源:IndexUpdate.java

示例6: 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);
		}
	}
}
 
開發者ID:carone1,項目名稱:ecs-dashboard,代碼行數:25,代碼來源:ElasticBucketOwnerDAO.java

示例7: prepareData

import org.elasticsearch.action.bulk.BulkResponse; //導入方法依賴的package包/類
private static void prepareData(IndicesAdminClient indicesAdminClient) throws InterruptedException {
    BulkRequestBuilder bulkRequestBuilder = client.prepareBulk();
    //批量添加
    for (int i = 0; i < 1000; i++) {
        ItemInfo iteminfo=new ItemInfo(i,"商品"+i, new Random().nextFloat(),new Date());
        // 當opType是Index時,如果文檔id存在,更新文檔,否則創建文檔 當opType是Create,如果文檔id存在,拋出文檔存在的錯誤 *
        IndexRequestBuilder indexRequestBuilder = client.prepareIndex(INDEX_NAME_v1, INDEX_TYPE).setId(i+"").setSource(JSONObject.toJSONString(iteminfo)).setOpType(IndexRequest.OpType.INDEX);
        bulkRequestBuilder.add(indexRequestBuilder);
        //數據日期不一樣
    }
    BulkResponse bulkResponse = bulkRequestBuilder.execute().actionGet();
    if (bulkResponse.hasFailures()) {
     log.error("bulk index error:{}",bulkResponse.buildFailureMessage());
    } else {
        log.info("index docs : {}" , bulkResponse);
    }
}
 
開發者ID:ggj2010,項目名稱:javabase,代碼行數:18,代碼來源:UpdateMappingFieldDemo.java

示例8: bulkIndex

import org.elasticsearch.action.bulk.BulkResponse; //導入方法依賴的package包/類
private void bulkIndex(String indexType, JsonNode data) {
    if (data.size() == 0) {
        return;
    }
    if (uniqueFields.size() > 0) {
        Set<String> keys = new HashSet<>();
        ArrayNode uniqued = Json.newArray();
        for (JsonNode point : data) {
            String key = FeatureExtractorUtilities.composeConcatenatedKey(point, dataFields);
            if (!keys.contains(key)) {
                keys.add(key);
                uniqued.add(point);
            }
        }
        data = uniqued;
    }
    BulkResponse resp = elasticSearchService.bulkIndex(elasticSearchIndex, indexType, data);
    if (resp.hasFailures()) {
        throw new BadRequestException(resp.buildFailureMessage());
    }
}
 
開發者ID:grouplens,項目名稱:samantha,代碼行數:22,代碼來源:ESBasedIndexer.java

示例9: bulkDelete

import org.elasticsearch.action.bulk.BulkResponse; //導入方法依賴的package包/類
private void bulkDelete(String indexType, JsonNode data) {
    SearchHits hits = elasticSearchService
            .searchHitsByKeys(elasticSearchIndex, indexType, uniqueFields, uniqueFields, data);
    List<String> ids = new ArrayList<>();
    for (SearchHit hit : hits.getHits()) {
        if (hit != null) {
            ids.add(hit.getId());
        }
    }
    if (ids.size() == 0) {
        return;
    }
    BulkResponse resp = elasticSearchService.bulkDelete(elasticSearchIndex, indexType, ids);
    if (resp.hasFailures()) {
        throw new BadRequestException(resp.buildFailureMessage());
    }
}
 
開發者ID:grouplens,項目名稱:samantha,代碼行數:18,代碼來源:ESBasedIndexer.java

示例10: add

import org.elasticsearch.action.bulk.BulkResponse; //導入方法依賴的package包/類
public BulkResponse add(String indexName, String sensorType, Iterable<String> docs)
    throws IOException {
  BulkRequestBuilder bulkRequest = getClient().prepareBulk();
  for (String doc : docs) {
    IndexRequestBuilder indexRequestBuilder = getClient()
        .prepareIndex(indexName, sensorType + "_doc");

    indexRequestBuilder = indexRequestBuilder.setSource(doc);
    Map<String, Object> esDoc = JSONUtils.INSTANCE
        .load(doc, new TypeReference<Map<String, Object>>() {
        });
    indexRequestBuilder.setId((String) esDoc.get(Constants.GUID));
    Object ts = esDoc.get("timestamp");
    if (ts != null) {
      indexRequestBuilder = indexRequestBuilder.setTimestamp(ts.toString());
    }
    bulkRequest.add(indexRequestBuilder);
  }

  BulkResponse response = bulkRequest.execute().actionGet();
  if (response.hasFailures()) {
    throw new IOException(response.buildFailureMessage());
  }
  return response;
}
 
開發者ID:apache,項目名稱:metron,代碼行數:26,代碼來源:ElasticSearchComponent.java

示例11: bulkDelete

import org.elasticsearch.action.bulk.BulkResponse; //導入方法依賴的package包/類
@Override
public void bulkDelete(BulkDeleteRequest request) {
    if (request.ids == null || request.ids.isEmpty()) throw Exceptions.error("request.ids must not be empty");

    StopWatch watch = new StopWatch();
    String index = request.index == null ? this.index : request.index;
    BulkRequestBuilder builder = client().prepareBulk();
    for (String id : request.ids) {
        builder.add(client().prepareDelete(index, type, id));
    }
    long esTookTime = 0;
    try {
        BulkResponse response = builder.get();
        esTookTime = response.getTook().nanos();
        if (response.hasFailures()) throw new SearchException(response.buildFailureMessage());
    } catch (ElasticsearchException e) {
        throw new SearchException(e);   // due to elastic search uses async executor to run, we have to wrap the exception to retain the original place caused the exception
    } finally {
        long elapsedTime = watch.elapsedTime();
        ActionLogContext.track("elasticsearch", elapsedTime, 0, request.ids.size());
        logger.debug("bulkDelete, index={}, type={}, size={}, esTookTime={}, elapsedTime={}", index, type, request.ids.size(), esTookTime, elapsedTime);
        checkSlowOperation(elapsedTime);
    }
}
 
開發者ID:neowu,項目名稱:core-ng-project,代碼行數:25,代碼來源:ElasticSearchTypeImpl.java

示例12: processBulkRequests

import org.elasticsearch.action.bulk.BulkResponse; //導入方法依賴的package包/類
protected BulkResponse processBulkRequests(final List<IndexRequestBuilder> requests)
{
    if (requests.size() > 0)
    {
        final BulkRequestBuilder bulkRequest = searchClientService.getClient().prepareBulk();
        for (final IndexRequestBuilder indexRequestBuilder : requests)
        {
            bulkRequest.add(indexRequestBuilder);
        }
        logger.debug("Executing bulk index request for size:" + requests.size());
        final BulkResponse bulkResponse = bulkRequest.execute().actionGet();
        logger.debug("Bulk operation data index response total items is:" + bulkResponse.getItems().length);
        if (bulkResponse.hasFailures())
        {
            // process failures by iterating through each bulk response item
            logger.error("bulk operation indexing has failures:" + bulkResponse.buildFailureMessage());
        }
        return bulkResponse;
    }
    else
    {
        logger.debug("Executing bulk index request for size: 0");
        return null;
    }
}
 
開發者ID:jaibeermalik,項目名稱:elasticsearch-akka,代碼行數:26,代碼來源:IndexProductDataServiceImpl.java

示例13: processBulkRequests

import org.elasticsearch.action.bulk.BulkResponse; //導入方法依賴的package包/類
protected BulkResponse processBulkRequests(
		final List<IndexRequestBuilder> requests) {
	if (requests.size() > 0) {
		final BulkRequestBuilder bulkRequest = searchClientService
				.getClient().prepareBulk();
		for (final IndexRequestBuilder indexRequestBuilder : requests) {
			bulkRequest.add(indexRequestBuilder);
		}
		logger.debug("Executing bulk index request for size:"
				+ requests.size());
		final BulkResponse bulkResponse = bulkRequest.execute().actionGet();
		logger.debug("Bulk operation data index response total items is:"
				+ bulkResponse.getItems().length);
		if (bulkResponse.hasFailures()) {
			// process failures by iterating through each bulk response item
			logger.error("bulk operation indexing has failures:"
					+ bulkResponse.buildFailureMessage());
		}
		return bulkResponse;
	} else {
		logger.debug("Executing bulk index request for size: 0");
		return null;
	}
}
 
開發者ID:jaibeermalik,項目名稱:searchanalytics-bigdata,代碼行數:25,代碼來源:IndexProductDataServiceImpl.java

示例14: testBulk

import org.elasticsearch.action.bulk.BulkResponse; //導入方法依賴的package包/類
@Test
public void testBulk() throws Exception {
    BulkRequestBuilder bulkRequest = client.prepareBulk();

    // either use client#prepare, or use Requests# to directly build
    // index/delete requests
    bulkRequest.add(client.prepareIndex("twitter", "tweet", "1").setSource(XContentFactory.jsonBuilder().startObject().field("user", "kimchy")
            .field("postDate", new Date()).field("message", "trying out Elasticsearch").endObject()));

    bulkRequest.add(client.prepareIndex("twitter", "tweet", "2").setSource(XContentFactory.jsonBuilder().startObject().field("user", "kimchy")
            .field("postDate", new Date()).field("message", "another post").endObject()));

    BulkResponse bulkResponse = bulkRequest.get();
    if (bulkResponse.hasFailures()) {
        // process failures by iterating through each bulk response item
    }
}
 
開發者ID:dzh,項目名稱:jframe,代碼行數:18,代碼來源:TestTransportClient.java

示例15: saveBatch

import org.elasticsearch.action.bulk.BulkResponse; //導入方法依賴的package包/類
public List<T> saveBatch(List<T> entities) throws Exception {
    List<T> result = new ArrayList<>();
    BulkRequestBuilder bulkRequest = client.prepareBulk();

    for (T entity : entities) {
        String id = mapping.id(entity);
        String index = mapping.index(entity);
        String type = mapping.type(entity);
        String source = mapping.toDocument(entity);
        bulkRequest.add(client.prepareIndex(index, type, id).setSource(source));
        result.add(entity);
    }

    BulkResponse bulkResponse = bulkRequest.execute().actionGet();
    if (bulkResponse.hasFailures()) {
        log.error("Bulk ingest has errors");
    }
    return result;
}
 
開發者ID:scaleset,項目名稱:scaleset-search,代碼行數:20,代碼來源:ElasticSearchDao.java


注:本文中的org.elasticsearch.action.bulk.BulkResponse.hasFailures方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。