本文整理匯總了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());
}
示例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());
}
示例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();
}
}
示例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();
}
}
示例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;
}
示例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
}
}
示例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);
}
}
示例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);
}
}
}
示例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++;
}
}
}
示例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();
}
}
}
示例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");
}
}
示例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();
}
}
示例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);
}
示例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();
}
示例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());
}
}