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


Java BulkResponse.buildFailureMessage方法代码示例

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


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

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: deleteByQuery

import org.elasticsearch.action.bulk.BulkResponse; //导入方法依赖的package包/类
public static boolean deleteByQuery(final Client client, final String index, final String type, final QueryBuilder queryBuilder) {
    try {
        SearchResponse searchResponse =
                client.prepareSearch(index).setTypes(type).setQuery(queryBuilder).setSize(500)
                        .setScroll(TimeValue.timeValueSeconds(10)).execute().actionGet();

        while (searchResponse.getHits().getHits().length > 0) {
            final String scrollId = searchResponse.getScrollId();
            final SearchHit[] hits = searchResponse.getHits().getHits();

            final BulkRequestBuilder bulkRequestBuiler = client.prepareBulk();
            Stream.of(hits).map(SearchHit::getId).forEach(id -> bulkRequestBuiler.add(new DeleteRequest(index, type, id)));

            final BulkResponse bulkResponse = bulkRequestBuiler.execute().actionGet();
            if (bulkResponse.hasFailures()) {
                throw new SuggesterException(bulkResponse.buildFailureMessage());
            }
            searchResponse = client.prepareSearchScroll(scrollId).setScroll(TimeValue.timeValueSeconds(10)).execute().actionGet();
        }
        client.admin().indices().prepareRefresh(index).execute().actionGet();
    } catch (final Exception e) {
        throw new SuggesterException("Failed to exec delete by query.", e);
    }

    return true;
}
 
开发者ID:codelibs,项目名称:fess-suggest,代码行数:27,代码来源:SuggestUtil.java

示例6: 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());
		}
	}
}
 
开发者ID:searchisko,项目名称:elasticsearch-river-remote,代码行数:23,代码来源:RemoteRiver.java

示例7: execute

import org.elasticsearch.action.bulk.BulkResponse; //导入方法依赖的package包/类
@Override
public void execute() throws Exception {
  try {
    BulkResponse bulkResponse = bulkRequestBuilder.execute().actionGet();
    if (bulkResponse.hasFailures()) {
      throw new EventDeliveryException(bulkResponse.buildFailureMessage());
    }
  } finally {
    bulkRequestBuilder = client.prepareBulk();
  }
}
 
开发者ID:moueimei,项目名称:flume-release-1.7.0,代码行数:12,代码来源:ElasticSearchTransportClient.java

示例8: flushIndex

import org.elasticsearch.action.bulk.BulkResponse; //导入方法依赖的package包/类
private void flushIndex(boolean force) {
	if ((force && this.bulkRequestCounter > 0)
			|| this.bulkRequestCounter >= this.bulkSize) {
		BulkResponse bulkResponse = this.bulkRequest.execute().actionGet();
		if (bulkResponse.hasFailures()) {
			throw new DukeException(bulkResponse.buildFailureMessage());
		}
		// reset bulk
		this.bulkRequestCounter = 0;
		this.bulkRequest = this.client.prepareBulk();
	}
}
 
开发者ID:enricopal,项目名称:STEM,代码行数:13,代码来源:ElasticSearchDatabase.java

示例9: commit

import org.elasticsearch.action.bulk.BulkResponse; //导入方法依赖的package包/类
@Override
public void commit() {
    if (bulkRequest.numberOfActions() > 0) {
        final BulkResponse bulkResponse = bulkRequest.get();
        if (bulkResponse.hasFailures())
            throw new RuntimeException(bulkResponse.buildFailureMessage());
    }
}
 
开发者ID:marozau,项目名称:expresso,代码行数:9,代码来源:ElasticSearchIndexer.java

示例10: execute

import org.elasticsearch.action.bulk.BulkResponse; //导入方法依赖的package包/类
@Override
public void execute() throws Exception {
    try {
        BulkResponse bulkResponse = bulkRequestBuilder.execute().actionGet();
        if (bulkResponse.hasFailures()) {
            throw new EventDeliveryException(bulkResponse.buildFailureMessage());
        }
    } finally {
        bulkRequestBuilder = client.prepareBulk();
    }
}
 
开发者ID:Redliver,项目名称:flume-ng-elasticsearch5-sink,代码行数:12,代码来源:ElasticSearchTransportClient.java

示例11: storeSpan

import org.elasticsearch.action.bulk.BulkResponse; //导入方法依赖的package包/类
@Override
public void storeSpan(String tenantId, List<Span> spans, Function<Span, String> spanIdSupplier)
        throws StoreException {

    client.initTenant(tenantId);

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

    for (Span span : spans) {
        String json;
        try {
            json = serialize(span);
        } catch(IOException ex){
            log.errorf("Failed to serialize span %s", span);
            throw new StoreException(ex);
        }

        log.tracef("Storing span: %s", json);
        // modified id is used in index
        final String modifiedId = spanIdSupplier.apply(span);

        bulkRequestBuilder.add(client.getClient()
                .prepareIndex(client.getIndex(tenantId), SPAN_TYPE, modifiedId)
                .setSource(json));
    }

    BulkResponse bulkItemResponses = bulkRequestBuilder.execute().actionGet();

    if (bulkItemResponses.hasFailures()) {
        log.tracef("Failed to store spans to elasticsearch: %s", bulkItemResponses.buildFailureMessage());
        throw new StoreException(bulkItemResponses.buildFailureMessage());
    }

    log.trace("Success storing spans to elasticsearch");
}
 
开发者ID:hawkular,项目名称:hawkular-apm,代码行数:36,代码来源:SpanServiceElasticsearch.java

示例12: bulkStoreApmEvents

import org.elasticsearch.action.bulk.BulkResponse; //导入方法依赖的package包/类
private void bulkStoreApmEvents(String tenantId, List<? extends ApmEvent> events, String type) throws StoreException {
    client.initTenant(tenantId);

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

    for (ApmEvent event : events) {
        String json = toJson(event);
        if (null == json) {
            continue;
        }

        if (msgLog.isTraceEnabled()) {
            msgLog.tracef("Storing event: %s", json);
        }

        bulkRequestBuilder.add(toIndexRequestBuilder(client, tenantId, type, event.getId(), json));
    }

    BulkResponse bulkItemResponses = bulkRequestBuilder.execute().actionGet();

    if (bulkItemResponses.hasFailures()) {
        if (msgLog.isTraceEnabled()) {
            msgLog.trace("Failed to store event to elasticsearch: " + bulkItemResponses.buildFailureMessage());
        }
        throw new StoreException(bulkItemResponses.buildFailureMessage());
    } else {
        if (msgLog.isTraceEnabled()) {
            msgLog.trace("Success storing event to elasticsearch");
        }
    }
}
 
开发者ID:hawkular,项目名称:hawkular-apm,代码行数:32,代码来源:AnalyticsServiceElasticsearch.java

示例13: storeFragments

import org.elasticsearch.action.bulk.BulkResponse; //导入方法依赖的package包/类
@Override
public void storeFragments(String tenantId, List<Trace> traces)
        throws StoreException {
    client.initTenant(tenantId);

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

    try {
        for (int i = 0; i < traces.size(); i++) {
            Trace trace = traces.get(i);
            String json = mapper.writeValueAsString(trace);

            if (msgLog.isTraceEnabled()) {
                msgLog.tracef("Storing trace: %s", json);
            }

            bulkRequestBuilder.add(client.getClient().prepareIndex(client.getIndex(tenantId),
                    TRACE_TYPE, trace.getFragmentId()).setSource(json));
        }
    } catch (JsonProcessingException e) {
        throw new StoreException(e);
    }

    BulkResponse bulkItemResponses = bulkRequestBuilder.execute().actionGet();

    if (bulkItemResponses.hasFailures()) {

        if (msgLog.isTraceEnabled()) {
            msgLog.trace("Failed to store traces to elasticsearch: "
                    + bulkItemResponses.buildFailureMessage());
        }

        throw new StoreException(bulkItemResponses.buildFailureMessage());

    } else {
        if (msgLog.isTraceEnabled()) {
            msgLog.trace("Success storing traces to elasticsearch");
        }
    }
}
 
开发者ID:hawkular,项目名称:hawkular-apm,代码行数:41,代码来源:TraceServiceElasticsearch.java

示例14: bulkIndex

import org.elasticsearch.action.bulk.BulkResponse; //导入方法依赖的package包/类
@Override
public void bulkIndex(BulkIndexRequest<T> request) {
    if (request.sources == null || request.sources.isEmpty()) throw Exceptions.error("request.sources must not be empty");

    StopWatch watch = new StopWatch();
    String index = request.index == null ? this.index : request.index;
    BulkRequestBuilder builder = client().prepareBulk();
    for (Map.Entry<String, T> entry : request.sources.entrySet()) {
        String id = entry.getKey();
        T source = entry.getValue();
        validator.validate(source);
        byte[] document = writer.toJSON(source);
        builder.add(client().prepareIndex(index, type, id).setSource(document, XContentType.JSON));
    }
    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.sources.size());
        logger.debug("bulkIndex, index={}, type={}, size={}, esTookTime={}, elapsedTime={}", index, type, request.sources.size(), esTookTime, elapsedTime);
        checkSlowOperation(elapsedTime);
    }
}
 
开发者ID:neowu,项目名称:core-ng-project,代码行数:29,代码来源:ElasticSearchTypeImpl.java

示例15: 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;
}
 
开发者ID:apache,项目名称:metron,代码行数:28,代码来源:ElasticsearchWriter.java


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