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


Java BulkRequestBuilder.numberOfActions方法代码示例

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


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

示例1: indexAll

import org.elasticsearch.action.bulk.BulkRequestBuilder; //导入方法依赖的package包/类
@Override
public <P extends ParaObject> void indexAll(String appid, List<P> objects) {
	if (StringUtils.isBlank(appid) || objects == null || objects.isEmpty()) {
		return;
	}
	BulkRequestBuilder brb = client().prepareBulk();
	for (ParaObject po : objects) {
		brb.add(client().prepareIndex(getIndexName(appid), getType(), po.getId()).
				setSource(ElasticSearchUtils.getSourceFromParaObject(po)));
	}
	if (brb.numberOfActions() > 0) {
		ActionListener<BulkResponse> responseHandler = ElasticSearchUtils.getBulkIndexResponseHandler();
		if (isAsyncEnabled()) {
			brb.execute(responseHandler);
		} else {
			responseHandler.onResponse(brb.execute().actionGet());
		}
	}
	logger.debug("Search.indexAll() {}", objects.size());
}
 
开发者ID:Erudika,项目名称:para-search-elasticsearch,代码行数:21,代码来源:ElasticSearch.java

示例2: unindexAll

import org.elasticsearch.action.bulk.BulkRequestBuilder; //导入方法依赖的package包/类
@Override
public <P extends ParaObject> void unindexAll(String appid, List<P> objects) {
	if (StringUtils.isBlank(appid) || objects == null || objects.isEmpty()) {
		return;
	}
	BulkRequestBuilder brb = client().prepareBulk();
	for (ParaObject po : objects) {
		brb.add(client().prepareDelete(getIndexName(appid), getType(), po.getId()));
	}
	if (brb.numberOfActions() > 0) {
		ActionListener<BulkResponse> responseHandler = ElasticSearchUtils.getBulkIndexResponseHandler();
		if (isAsyncEnabled()) {
			brb.execute(responseHandler);
		} else {
			responseHandler.onResponse(brb.execute().actionGet());
		}
	}
	logger.debug("Search.unindexAll() {}", objects.size());
}
 
开发者ID:Erudika,项目名称:para-search-elasticsearch,代码行数:20,代码来源:ElasticSearch.java

示例3: dropClass

import org.elasticsearch.action.bulk.BulkRequestBuilder; //导入方法依赖的package包/类
public void dropClass(final String className) {
  SearchResponse scrollResponse = esClient.getClient().prepareSearch(getIndexName()).setTypes(className)
      .setSearchType(SearchType.SCAN).setScroll(new TimeValue(60000)).setQuery(QueryBuilders.matchAllQuery()).setSize(100).get();
  final BulkRequestBuilder bulkRequestBuilder = esClient.getClient().prepareBulk().setRefresh(true);
  while (true) {
    if (scrollResponse.getHits().getHits().length == 0) {
      break;
    }

    for (SearchHit hit : scrollResponse.getHits().getHits()) {
      bulkRequestBuilder.add(esClient.getClient().prepareDelete(getIndexName(), className, hit.getId()));
    }

    scrollResponse = esClient.getClient().prepareSearchScroll(scrollResponse.getScrollId()).setScroll(new TimeValue(60000)).get();
  }
  if (bulkRequestBuilder.numberOfActions() > 0) {
    bulkRequestBuilder.get();
  }
}
 
开发者ID:orientechnologies,项目名称:orientdb-elasticsearch,代码行数:20,代码来源:OElasticSearchDatabaseSync.java

示例4: run

import org.elasticsearch.action.bulk.BulkRequestBuilder; //导入方法依赖的package包/类
@Override
public void run() {
    SearchResponse searchResponse = client.prepareSearch(searchIndex)
            .setTypes("Document")
            .setQuery(QueryBuilders.boolQuery()
                    .mustNot(QueryBuilders.hasChildQuery("DocumentInSystem", QueryBuilders.matchAllQuery())))
            .setSize(9999)
            .get();

    BulkRequestBuilder bulkRequestBuilder = client.prepareBulk();
    for (SearchHit searchHit : searchResponse.getHits().hits()) {
        DeleteRequestBuilder delete = client.prepareDelete(searchIndex, "Document", searchHit.getId());
        bulkRequestBuilder.add(delete);
    }

    if (bulkRequestBuilder.numberOfActions() > 0) {
        bulkRequestBuilder.get();
    }
}
 
开发者ID:nlpie,项目名称:nlptab,代码行数:20,代码来源:DeleteOrphanedDocuments.java

示例5: execute

import org.elasticsearch.action.bulk.BulkRequestBuilder; //导入方法依赖的package包/类
/**
 * Executes the list with requests as a bulk with maximum number of requests per bulk
 * @param requests
 * @param maxRequestsPerBulk
 * @return
 * @throws SQLException
 */
private int execute(List<?> requests, int maxRequestsPerBulk) throws SQLException{
	int result = 0;
	BulkRequestBuilder bulkReq = client.prepareBulk();
	for(Object req : requests){
		if(req instanceof IndexRequest)	bulkReq.add((IndexRequest)req);
		else if(req instanceof UpdateRequest) bulkReq.add((UpdateRequest)req);
		else if(req instanceof DeleteRequest) bulkReq.add((DeleteRequest)req);
		else if(req instanceof IndexRequestBuilder) bulkReq.add((IndexRequestBuilder)req);
		else if(req instanceof UpdateRequestBuilder) bulkReq.add((UpdateRequestBuilder)req);
		else if(req instanceof DeleteRequestBuilder) bulkReq.add((DeleteRequestBuilder)req);
		else throw new SQLException("Type "+req.getClass()+" cannot be added to a bulk request");
		
		if(bulkReq.numberOfActions() > maxRequestsPerBulk){
			result += bulkReq.get().getItems().length;
			bulkReq = client.prepareBulk();
		}
	}
	
	if(bulkReq.numberOfActions() > 0){
		result += bulkReq.get().getItems().length;
	}
	return result;
}
 
开发者ID:Anchormen,项目名称:sql4es,代码行数:31,代码来源:ESUpdateState.java

示例6: beforeTest

import org.elasticsearch.action.bulk.BulkRequestBuilder; //导入方法依赖的package包/类
@Before
public void beforeTest() throws Exception{
	jCas = JCasSingleton.getJCasInstance();

	try{
		//Find all documents in index and delete the documents
		BulkRequestBuilder brb = client.prepareBulk();
		SearchHits results = client.search(new SearchRequest()).actionGet().getHits();
		for(SearchHit sh : results){
			brb.add(client.prepareDelete("baleen_index", "baleen_output", sh.getId()).request());
		}
		if(brb.numberOfActions() > 0)
			brb.get();
	}catch(IndexNotFoundException infe){
		//Index doesn't exist - ignore
	}
}
 
开发者ID:dstl,项目名称:baleen,代码行数:18,代码来源:ElasticsearchTestBase.java

示例7: processBulkRequest

import org.elasticsearch.action.bulk.BulkRequestBuilder; //导入方法依赖的package包/类
private void processBulkRequest(BulkRequestBuilder bulkRequest, int blCount) {
    if (bulkRequest.numberOfActions() == 0) {
        return;
    }

    int currentNo = batchNo.incrementAndGet();
    logger.info("Processing bulk request {}.", currentNo);

    BulkResponse bulkResponse = bulkRequest.execute().actionGet();
    if (bulkResponse.hasFailures()) {
        logger.error("Bulk response failure! (this is bad) Request: {}, message: {}", currentNo, bulkResponse.getItems()[0].getFailureMessage());
        throw new ImportException(bulkResponse.getItems()[0].getFailureMessage());
    } else {
        logger.info("{} docs were processed by request {} with blCount of {}.", bulkRequest.numberOfActions(), currentNo, blCount);
    }
}
 
开发者ID:korobi,项目名称:ElasticMangos,代码行数:17,代码来源:ChatDocumentProcessor.java

示例8: bulkUpdateIndices

import org.elasticsearch.action.bulk.BulkRequestBuilder; //导入方法依赖的package包/类
public void bulkUpdateIndices(List<TridentTuple> inputs, TridentTupleMapper<Document<T>> mapper, BulkResponseHandler handler) {
    BulkRequestBuilder bulkRequest = client.prepareBulk();
    for (TridentTuple input : inputs) {
        Document<T> doc = mapper.map(input);
        byte[] source = serializeSourceOrFail(doc);
        IndexRequestBuilder request = client.prepareIndex(doc.getName(), doc.getType(), doc.getId()).setSource(source);

        if(doc.getParentId() != null) {
            request.setParent(doc.getParentId());
        }
        bulkRequest.add(request);
    }

    if( bulkRequest.numberOfActions() > 0) {
        try {
            handler.handle(bulkRequest.execute().actionGet());
        } catch(ElasticsearchException e) {
            LOGGER.error("error while executing bulk request to elasticsearch");
            throw new FailedException("Failed to store data into elasticsearch", e);
        }
    }
}
 
开发者ID:fhussonnois,项目名称:storm-trident-elasticsearch,代码行数:23,代码来源:ESIndexState.java

示例9: executeBuilder

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

示例10: run

import org.elasticsearch.action.bulk.BulkRequestBuilder; //导入方法依赖的package包/类
@Override
public void run() {
	logger.info("Starting thread with {} keys", this.keys.rowColumnMap.size());
              if (closed) {
                  return;
              }
              
              BulkRequestBuilder bulk = client.prepareBulk();
              for(String key : this.keys.rowColumnMap.keySet()){
              	
  				try {
  					String id = UUID.nameUUIDFromBytes(key.getBytes()).toString();
  					bulk.add(indexRequest(this.indexName).type(this.typeName)
					    							 .id(id)
					    							 .source(this.keys.rowColumnMap.get(key)));
  				} catch (Exception e) {
  					logger.error("failed to entry to bulk indexing");
  				}
  				
              	if(bulk.numberOfActions() >= this.batchSize){
              		saveToEs(bulk);
  					bulk = client.prepareBulk();
              	}
              }
}
 
开发者ID:eBay,项目名称:cassandra-river,代码行数:26,代码来源:CassandraRiver.java

示例11: runBulk

import org.elasticsearch.action.bulk.BulkRequestBuilder; //导入方法依赖的package包/类
private void runBulk(BulkRequestBuilder bulkRequest) {
    if(bulkRequest.numberOfActions() > 0) {
        int tryCount = 0;
        boolean shouldTryAgain;
        do {
            shouldTryAgain = false;
            try {                
                BulkResponse bulkResponse = bulkRequest.execute().actionGet();
                if (bulkResponse.hasFailures()) {
                    shouldTryAgain = this.exceptionHandler.onBulkRequestFailure(bulkResponse, tryCount);
                    tryCount++;
                }
            } catch (ElasticsearchException e) {
                shouldTryAgain = this.exceptionHandler.onElasticSearchException(e, tryCount);
                tryCount++;
            }
        } while (shouldTryAgain);
    } else {
        LOG.debug("Empty batch being submitted");
    }
}
 
开发者ID:hmsonline,项目名称:trident-elasticsearch,代码行数:22,代码来源:IndexState.java

示例12: executeDelete

import org.elasticsearch.action.bulk.BulkRequestBuilder; //导入方法依赖的package包/类
public void executeDelete() {
    Preconditions.checkNotNull(indexes);
    Preconditions.checkNotNull(types);
    Preconditions.checkNotNull(queryBuilder);

    SearchResponse searchResponse = client.prepareSearch(indexes)
            .setTypes(types)
            .setScroll(new TimeValue(60, TimeUnit.SECONDS))
            .setSize(500)
            .setQuery(queryBuilder)
            .get();

    BulkRequestBuilder bulkRequestBuilder = client.prepareBulk();

    while (true) {
        searchResponse = client.prepareSearchScroll(searchResponse.getScrollId())
                .setScroll(new TimeValue(60, TimeUnit.SECONDS))
                .get();
        SearchHit[] hits = searchResponse.getHits().hits();
        if (hits.length == 0) {
            break;
        }

        for (SearchHit searchHit : hits) {
            DeleteRequestBuilder delete = client.prepareDelete(searchHit.index(), searchHit.type(),
                    searchHit.id());

            bulkRequestBuilder.add(delete);
        }
    }

    client.prepareClearScroll()
            .addScrollId(searchResponse.getScrollId())
            .get();

    if (bulkRequestBuilder.numberOfActions() > 0) {
        bulkRequestBuilder.get();
    }
}
 
开发者ID:nlpie,项目名称:nlptab,代码行数:40,代码来源:ScrollDeleter.java

示例13: process

import org.elasticsearch.action.bulk.BulkRequestBuilder; //导入方法依赖的package包/类
void process() throws NlpTabException {
    BulkRequestBuilder bulkRequestBuilder = client.prepareBulk();

    casProcessingDelegate.priorToProcessing(sofaData);
    int processed = 0;
    try {
        while (!fsRefQueue.isEmpty()) {
            Integer fsRef = fsRefQueue.poll(POLL_FS_QUEUE_EVERY_MS, TimeUnit.MILLISECONDS);
            if (fsRef == null) {
                continue;
            }
            FeatureStructure featureStructure = lowLevelCAS.ll_getFSForRef(fsRef);

            casProcessingDelegate.willProcess(featureStructure, typeSystemInfo);

            if (LOGGER.isTraceEnabled()) {
                LOGGER.trace("Processing feature structure with type {}", featureStructure.getType().getName());
            }

            IndexRequestBuilder indexRequestBuilder = featureStructureProcessorFactory
                    .create(casProcessorSettings, sofaData, featureStructure)
                    .process();

            if (indexRequestBuilder != null) {
                bulkRequestBuilder.add(indexRequestBuilder);
            }
            processed++;
        }
        if (bulkRequestBuilder.numberOfActions() > 0) {
            bulkRequestBuilder.get();
        }
        casProcessingDelegate.afterProcessing(sofaData);
    } catch (InterruptedException | IOException e) {
        throw new NlpTabException("Interrupted while attempting to upload search sofa", e);
    }
    LOGGER.debug("Number of FeatureStructures processed: {}", processed);
}
 
开发者ID:nlpie,项目名称:nlptab,代码行数:38,代码来源:CasViewProcessor.java

示例14: executeBulk

import org.elasticsearch.action.bulk.BulkRequestBuilder; //导入方法依赖的package包/类
private Optional<BulkResult> executeBulk(int indexedCount, BulkRequestBuilder bulkRequest) {
  if (bulkRequest.numberOfActions() > 0) {
    BulkResponse bulkItemResponses = bulkRequest.execute().actionGet();
    Set<String> failedIds = Stream.of(bulkItemResponses.getItems())
        .filter(BulkItemResponse::isFailed)
        .map(BulkItemResponse::getId)
        .collect(Collectors.toSet());
    return Optional.of(new BulkResult(indexedCount, failedIds));
  }
  return Optional.empty();
}
 
开发者ID:allegro,项目名称:elasticsearch-reindex-tool,代码行数:12,代码来源:IndexingComponent.java

示例15: processBulkRequest

import org.elasticsearch.action.bulk.BulkRequestBuilder; //导入方法依赖的package包/类
private void processBulkRequest(BulkRequestBuilder bulkRequest) {
    if (bulkRequest.numberOfActions() == 0) {
        return;
    }

    BulkResponse bulkResponse = bulkRequest.execute().actionGet();
    if (bulkResponse.hasFailures()) {
        logger.error("Bulk response failure! (this is bad!) Message: {}", bulkResponse.getItems()[0].getFailureMessage());
        throw new ImportException(bulkResponse.getItems()[0].getFailureMessage());
    } else {
        logger.info("{} channels were processed by the bulk request.", bulkRequest.numberOfActions());
    }
}
 
开发者ID:korobi,项目名称:ElasticMangos,代码行数:14,代码来源:ChannelDocumentProcessor.java


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