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


Java BulkRequestBuilder.execute方法代碼示例

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


在下文中一共展示了BulkRequestBuilder.execute方法的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: createMapping

import org.elasticsearch.action.bulk.BulkRequestBuilder; //導入方法依賴的package包/類
/**
 * Create a mapping over an index
 *
 * @param indexName
 * @param mappingName
 * @param mappingSource the data that has to be inserted in the mapping.
 */
public void createMapping(String indexName, String mappingName, ArrayList<XContentBuilder> mappingSource) {
    IndicesExistsResponse existsResponse = this.client.admin().indices().prepareExists(indexName).execute()
            .actionGet();
    //If the index does not exists, it will be created without options
    if (!existsResponse.isExists()) {
        if (!createSingleIndex(indexName)) {
            throw new ElasticsearchException("Failed to create " + indexName
                    + " index.");
        }
    }
    BulkRequestBuilder bulkRequest = this.client.prepareBulk();
    for (int i = 0; i < mappingSource.size(); i++) {
        int aux = i + 1;

        IndexRequestBuilder res = this.client
                .prepareIndex(indexName, mappingName, String.valueOf(aux)).setSource(mappingSource.get(i));
        bulkRequest.add(res);
    }
    bulkRequest.execute();
}
 
開發者ID:Stratio,項目名稱:bdt,代碼行數:28,代碼來源:ElasticSearchUtils.java

示例4: deleteDocuments

import org.elasticsearch.action.bulk.BulkRequestBuilder; //導入方法依賴的package包/類
@Override
public void deleteDocuments(
        SearchContext searchContext, Collection<String> uids)
        throws SearchException {

    try {
        Client client = getClient();

        BulkRequestBuilder bulkRequestBuilder = client.prepareBulk();

        for (String uid : uids) {
        	  DeleteRequestBuilder deleteRequestBuilder =
                      client.prepareDelete(
                              Utilities.getIndexName(searchContext),
                              "documents", uid);

            bulkRequestBuilder.add(deleteRequestBuilder);
        }

        Future<BulkResponse> future = bulkRequestBuilder.execute();

        BulkResponse bulkResponse = future.get();
        if(_log.isDebugEnabled())
        {
        	if(bulkResponse.hasFailures())
        	{
        		_log.debug("Errors while doing bulk delete with errors " + bulkResponse.buildFailureMessage() );
        	}
        }

    } catch (Exception e) {
        throw new SearchException("Unable to delete documents " + uids, e);
    }
}
 
開發者ID:R-Knowsys,項目名稱:elasticray,代碼行數:35,代碼來源:ElasticsearchIndexWriter.java

示例5: executeBulkRequest

import org.elasticsearch.action.bulk.BulkRequestBuilder; //導入方法依賴的package包/類
private void executeBulkRequest(final StreamInput streamInput, final BulkRequestBuilder builder) {
    builder.execute(wrap(res -> {
        processRequests(streamInput);
        // continue
    }, e -> {
        if (senderRequestRetryCount >= 0) {
            if (requestErrorCount > senderRequestRetryCount) {
                logger.error("[Sender][" + index + "][" + requestErrorCount + "] Failed to process the bulk request.", e);
                requestErrorCount = 0;
                writeError(requestPosition, builder.request(), wrap(r -> processRequests(streamInput), ex -> {
                    logger.warn("Failed to store an error request.", ex);
                    processRequests(streamInput);
                }));
            } else {
                if (logger.isDebugEnabled()) {
                    logger.debug("[Sender][" + index + "][" + requestErrorCount + "] Failed to process the bulk request.", e);
                }
                requestErrorCount++;
                executeBulkRequest(streamInput, builder);
            }
        } else {
            IOUtils.closeQuietly(streamInput);
            retryWithError("Failed to process (" + builder.request() + ")", e);
            // retry
        }
    }));
}
 
開發者ID:codelibs,項目名稱:elasticsearch-indexing-proxy,代碼行數:28,代碼來源:RequestSender.java

示例6: CopyIndex

import org.elasticsearch.action.bulk.BulkRequestBuilder; //導入方法依賴的package包/類
public void CopyIndex(Client sourceclient, String sourceindex, Client targetclient, String targetindex) {
	// TODO Auto-generated method stub
	count = 0;
	QueryBuilder qb = QueryBuilders.matchAllQuery();

	try {

		SearchResponse scrollResp = sourceclient.prepareSearch(sourceindex)
				.addSort(FieldSortBuilder.DOC_FIELD_NAME, SortOrder.ASC).setScroll(new TimeValue(60000))
				.setQuery(qb).setSize(500).execute().actionGet();

		while (true) {
			final BulkRequestBuilder bulkRequest = targetclient.prepareBulk();
			for (SearchHit hit : scrollResp.getHits().getHits()) {
				bulkRequest.add(targetclient.prepareIndex(targetindex, hit.getType().toString(), hit.getId())
						.setSource(hit.getSourceAsString()));
				count++;
			}

			bulkRequest.execute();
			scrollResp = sourceclient.prepareSearchScroll(scrollResp.getScrollId()).setScroll(new TimeValue(60000))
					.execute().actionGet();

			logger.info(count + " documents putted!!");

			if (scrollResp.getHits().getHits().length == 0) {
				break;
			}
		}

		logger.info("copy index " + sourceindex + " " + count + " documents" + " to " + targetindex + " complete");
	} catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}
 
開發者ID:jiashiwen,項目名稱:elasticbak,代碼行數:37,代碼來源:ElasticsearchCopyIndex.java

示例7: CopyIndexByQueryDsl

import org.elasticsearch.action.bulk.BulkRequestBuilder; //導入方法依賴的package包/類
public void CopyIndexByQueryDsl(Client sourceclient, String sourceindex, Client targetclient, String targetindex,
		String DSL) {
	count = 0;
	// 單線程scroll,bulk寫入
	WrapperQueryBuilder wrapper = new WrapperQueryBuilder(DSL);

	try {
		SearchResponse scrollResp = sourceclient.prepareSearch(sourceindex)
				.addSort(FieldSortBuilder.DOC_FIELD_NAME, SortOrder.ASC).setScroll(new TimeValue(60000))
				.setQuery(wrapper).setSize(500).execute().actionGet();

		while (true) {
			final BulkRequestBuilder bulkRequest = targetclient.prepareBulk();
			for (SearchHit hit : scrollResp.getHits().getHits()) {
				bulkRequest.add(targetclient.prepareIndex(targetindex, hit.getType().toString(), hit.getId())
						.setSource(hit.getSourceAsString()));
				count++;
			}

			bulkRequest.execute();

			scrollResp = sourceclient.prepareSearchScroll(scrollResp.getScrollId()).setScroll(new TimeValue(60000))
					.execute().actionGet();
			logger.info(count + " documents putted!!");

			if (scrollResp.getHits().getHits().length == 0) {
				break;
			}
		}
		
		logger.info("copy index " + sourceindex + " " + count + " documents" + " to " + targetindex + " complete");
		
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
開發者ID:jiashiwen,項目名稱:elasticbak,代碼行數:37,代碼來源:ElasticsearchCopyIndex.java

示例8: CopyIndex

import org.elasticsearch.action.bulk.BulkRequestBuilder; //導入方法依賴的package包/類
public void CopyIndex(Client sourceclient, String sourceindex, Client targetclient, String targetindex) {
	// TODO Auto-generated method stub
	count = 0;
	QueryBuilder qb = QueryBuilders.matchAllQuery();

	try {

		SearchResponse scrollResp = sourceclient.prepareSearch(sourceindex)
				.addSort(SortParseElement.DOC_FIELD_NAME, SortOrder.ASC).setScroll(new TimeValue(60000))
				.setQuery(qb).setSize(500).execute().actionGet();

		while (true) {
			final BulkRequestBuilder bulkRequest = targetclient.prepareBulk();
			for (SearchHit hit : scrollResp.getHits().getHits()) {
				bulkRequest.add(targetclient.prepareIndex(targetindex, hit.getType().toString(), hit.getId())
						.setSource(hit.getSourceAsString()));
				count++;
			}

			bulkRequest.execute();
			scrollResp = sourceclient.prepareSearchScroll(scrollResp.getScrollId()).setScroll(new TimeValue(60000))
					.execute().actionGet();

			logger.info(count + " documents putted!!");

			if (scrollResp.getHits().getHits().length == 0) {
				break;
			}
		}

		logger.info("copy index " + sourceindex + " " + count + " documents" + " to " + targetindex + " complete");
	} catch (Exception e) {
		// TODO Auto-generated catch block
		e.printStackTrace();
	}
}
 
開發者ID:jiashiwen,項目名稱:elastictransfor,代碼行數:37,代碼來源:ElasticsearchCopyIndex.java

示例9: CopyIndexByQueryDsl

import org.elasticsearch.action.bulk.BulkRequestBuilder; //導入方法依賴的package包/類
public void CopyIndexByQueryDsl(Client sourceclient, String sourceindex, Client targetclient, String targetindex,
		String DSL) {
	count = 0;
	// 單線程scroll,bulk寫入
	WrapperQueryBuilder wrapper = new WrapperQueryBuilder(DSL);

	try {
		SearchResponse scrollResp = sourceclient.prepareSearch(sourceindex)
				.addSort(SortParseElement.DOC_FIELD_NAME, SortOrder.ASC).setScroll(new TimeValue(60000))
				.setQuery(wrapper).setSize(500).execute().actionGet();

		while (true) {
			final BulkRequestBuilder bulkRequest = targetclient.prepareBulk();
			for (SearchHit hit : scrollResp.getHits().getHits()) {
				bulkRequest.add(targetclient.prepareIndex(targetindex, hit.getType().toString(), hit.getId())
						.setSource(hit.getSourceAsString()));
				count++;
			}

			bulkRequest.execute();

			scrollResp = sourceclient.prepareSearchScroll(scrollResp.getScrollId()).setScroll(new TimeValue(60000))
					.execute().actionGet();
			logger.info(count + " documents putted!!");

			if (scrollResp.getHits().getHits().length == 0) {
				break;
			}
		}
		
		logger.info("copy index " + sourceindex + " " + count + " documents" + " to " + targetindex + " complete");
		
	} catch (Exception e) {
		e.printStackTrace();
	}
}
 
開發者ID:jiashiwen,項目名稱:elastictransfor,代碼行數:37,代碼來源:ElasticsearchCopyIndex.java

示例10: executeBulk

import org.elasticsearch.action.bulk.BulkRequestBuilder; //導入方法依賴的package包/類
/**
 * Executes the bulk request
 * @param bulk
 */
private static void executeBulk(BulkRequestBuilder bulk) {
	log.info("Executing bulk...");
	ListenableActionFuture<BulkResponse> futures = bulk.execute();
	BulkResponse response = futures.actionGet();

	log.info("Response: " + response.getTookInMillis());
}
 
開發者ID:brunocvcunha,項目名稱:jobstats,代碼行數:12,代碼來源:ElasticSearchHelper.java

示例11: sendToLocalCluster

import org.elasticsearch.action.bulk.BulkRequestBuilder; //導入方法依賴的package包/類
private void sendToLocalCluster(final String scrollId, final SearchHit[] hits) {

            // prepare bulk request
            final BulkRequestBuilder bulkRequest = client.prepareBulk();
            for (final SearchHit hit : hits) {
                IndexRequestBuilder builder = client.prepareIndex(toIndex,
                        toType != null ? toType : hit.getType(), hit.getId())
                        .setSource(hit.getSource());
                Map<String, SearchHitField> fields = hit.getFields();
                if (fields != null && fields.containsKey("_parent")) {
                    SearchHitField parentField = fields.get("_parent");
                    if (parentField != null) {
                        String parentId = parentField.getValue();
                        builder.setParent(parentId);
                    }
                }
                bulkRequest.add(builder);
            }

            // send bulk request, if success response got, searching the next 10 results using scroll_id
            // using this listener (inner class) to listen to results
            bulkRequest.execute(new ActionListener<BulkResponse>() {
                @Override
                public void onResponse(final BulkResponse bulkResponse) {
                    if (bulkResponse.hasFailures()) {
                        throw new ReindexingException(bulkResponse
                                .buildFailureMessage());
                    }
                    client.prepareSearchScroll(scrollId).setScroll(scroll)
                            .execute(ReindexingListener.this);
                }

                @Override
                public void onFailure(final Throwable e) {
                    ReindexingListener.this.onFailure(e);
                }
            });
        }
 
開發者ID:codelibs,項目名稱:elasticsearch-reindexing,代碼行數:39,代碼來源:ReindexingService.java

示例12: flush

import org.elasticsearch.action.bulk.BulkRequestBuilder; //導入方法依賴的package包/類
protected synchronized void flush() {
    if (resultQueue.isEmpty()) {
        return;
    }

    final Queue<Map<String, Object>> currentQueue = resultQueue;
    resultQueue = new ConcurrentLinkedQueue<>();

    final BulkRequestBuilder bulkRequest = client.prepareBulk();

    for (final Map<String, Object> obj : currentQueue) {
        bulkRequest.add(client.prepareIndex(index, type).setSource(obj));
    }

    bulkRequest.execute(new ActionListener<BulkResponse>() {
        @Override
        public void onResponse(final BulkResponse response) {
            if (response.hasFailures()) {
                logger.error("Failed to write a result on {}/{}: {}",
                        index, type, response.buildFailureMessage());
            } else {
                logger.info("Wrote {} results in {}/{}.",
                        currentQueue.size(), index, type);
            }
        }

        @Override
        public void onFailure(final Throwable e) {
            logger.error("Failed to write a result on {}/{}.", e, index,
                    type);
        }
    });
}
 
開發者ID:codelibs,項目名稱:elasticsearch-taste,代碼行數:34,代碼來源:ResultWriter.java

示例13: sendBulkInserts

import org.elasticsearch.action.bulk.BulkRequestBuilder; //導入方法依賴的package包/類
private void sendBulkInserts() {
	
	if (docs.isEmpty()) { return; }
	
	BulkRequestBuilder bulkRequestBuilder = null;
	try {

		synchronized (esClient) {
			TransportClient client = getClient();
			bulkRequestBuilder = client.prepareBulk();

			Iterator<EsDocument> iter = docs.iterator();
			while (iter.hasNext()) {
				EsDocument doc = iter.next();
				IndexRequestBuilder indexRequestBuilder = client.prepareIndex(doc.index,doc.type,doc.id).setSource(doc.doc);
				bulkRequestBuilder.add(indexRequestBuilder);
			}
		}
		ListenableActionFuture<BulkResponse> laf = bulkRequestBuilder.execute();
		if (sync) {
			laf.actionGet();
		}
		
	} catch (EsServerException e) {
		e.printStackTrace();
	}
	
	docs = new ArrayList<EsDocument>();
	bulkInsertCount = 0;
	bulkInsertSize = 0;
}
 
開發者ID:chrisGerken,項目名稱:rankenphile,代碼行數:32,代碼來源:EsDocumentSet.java

示例14: writeToNoSQL

import org.elasticsearch.action.bulk.BulkRequestBuilder; //導入方法依賴的package包/類
@Override
public void writeToNoSQL(List<Map<String, Object>> entityList) {

    BulkRequestBuilder bulkRequest = client.prepareBulk();

    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:bench,項目名稱:Sql2NoSql-Importer,代碼行數:29,代碼來源:ESWriter.java

示例15: excuteBulkRequestAsync

import org.elasticsearch.action.bulk.BulkRequestBuilder; //導入方法依賴的package包/類
/**
 * Excute bulk request async.
 *
 * @param bulkRequestBuilder
 *            the bulk request builder
 * @param bulkResponseActionListener
 *            the bulk response action listener
 */
public void excuteBulkRequestAsync(BulkRequestBuilder bulkRequestBuilder,
		ActionListener<BulkResponse> bulkResponseActionListener) {
	JMLog.info(log, "excuteBulkRequestAsync", bulkRequestBuilder,
			bulkResponseActionListener);
	bulkRequestBuilder.execute(bulkResponseActionListener);
}
 
開發者ID:JM-Lab,項目名稱:utils-elasticsearch,代碼行數:15,代碼來源:JMElasticsearchBulk.java


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