本文整理匯總了Java中org.elasticsearch.action.bulk.BulkRequestBuilder.get方法的典型用法代碼示例。如果您正苦於以下問題:Java BulkRequestBuilder.get方法的具體用法?Java BulkRequestBuilder.get怎麽用?Java BulkRequestBuilder.get使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在類org.elasticsearch.action.bulk.BulkRequestBuilder
的用法示例。
在下文中一共展示了BulkRequestBuilder.get方法的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: batchDelete
import org.elasticsearch.action.bulk.BulkRequestBuilder; //導入方法依賴的package包/類
/**
* 批量刪除
*
* @param transportClient
*/
private static void batchDelete(TransportClient transportClient) throws IOException {
BulkRequestBuilder bulkRequestBuilder = transportClient.prepareBulk();
DeleteRequestBuilder deleteRequestBuilder1 = transportClient.prepareDelete("product_index", "product", "1");
DeleteRequestBuilder deleteRequestBuilder2 = transportClient.prepareDelete("product_index", "product", "2");
DeleteRequestBuilder deleteRequestBuilder3 = transportClient.prepareDelete("product_index", "product", "3");
bulkRequestBuilder.add(deleteRequestBuilder1);
bulkRequestBuilder.add(deleteRequestBuilder2);
bulkRequestBuilder.add(deleteRequestBuilder3);
BulkResponse bulkResponse = bulkRequestBuilder.get();
for (BulkItemResponse bulkItemResponse : bulkResponse.getItems()) {
logger.info("--------------------------------version= " + bulkItemResponse.getVersion());
}
}
示例2: save
import org.elasticsearch.action.bulk.BulkRequestBuilder; //導入方法依賴的package包/類
@Nonnull
@Override
public List<T> save(@Nonnull final List<T> documents, @Nonnull final String indexName) {
Assert.notNull(documents, "The list of documents should not be null");
assertIndexNameNotNull(indexName);
final BulkRequestBuilder bulkBuilder = esClient.prepareBulk();
documents.forEach(document -> {
final IndexRequestBuilder indexRequestBuilder = esClient
.prepareIndex(indexName, getDocumentType())
.setId(document.getUuid())
.setSource(jsonComponent.serialize(document, clazz));
bulkBuilder.add(indexRequestBuilder);
});
bulkBuilder.get();
return documents;
}
示例3: batchUpdate
import org.elasticsearch.action.bulk.BulkRequestBuilder; //導入方法依賴的package包/類
/**
* 批量更新
*
* @param transportClient
*/
private static void batchUpdate(TransportClient transportClient) throws IOException {
BulkRequestBuilder bulkRequestBuilder = transportClient.prepareBulk();
UpdateRequestBuilder updateRequestBuilder1 = transportClient.prepareUpdate("product_index", "product", "1")
.setDoc(XContentFactory.jsonBuilder()
.startObject()
.field("product_name", "更新後的商品名稱1")
.endObject());
UpdateRequestBuilder updateRequestBuilder2 = transportClient.prepareUpdate("product_index", "product", "2")
.setDoc(XContentFactory.jsonBuilder()
.startObject()
.field("product_name", "更新後的商品名稱2")
.endObject());
UpdateRequestBuilder updateRequestBuilder3 = transportClient.prepareUpdate("product_index", "product", "3")
.setDoc(XContentFactory.jsonBuilder()
.startObject()
.field("product_name", "更新後的商品名稱3")
.endObject());
bulkRequestBuilder.add(updateRequestBuilder1);
bulkRequestBuilder.add(updateRequestBuilder2);
bulkRequestBuilder.add(updateRequestBuilder3);
BulkResponse bulkResponse = bulkRequestBuilder.get();
for (BulkItemResponse bulkItemResponse : bulkResponse.getItems()) {
logger.info("--------------------------------version= " + bulkItemResponse.getVersion());
}
}
示例4: createIndex
import org.elasticsearch.action.bulk.BulkRequestBuilder; //導入方法依賴的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 + " 條記錄==========================");
}
}
示例5: deleteES
import org.elasticsearch.action.bulk.BulkRequestBuilder; //導入方法依賴的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");
}
}
示例6: insertThreadObjectToES
import org.elasticsearch.action.bulk.BulkRequestBuilder; //導入方法依賴的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());
}
}
示例7: 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();
}
}
示例8: bulkIndex
import org.elasticsearch.action.bulk.BulkRequestBuilder; //導入方法依賴的package包/類
public <T> BulkResponse bulkIndex(String indexName, List<T> sources) {
BulkRequestBuilder bulkRequestBuilder = client.prepareBulk();
sources
.parallelStream()
.map(src -> {
try {
return Optional.of(objectMapper.writeValueAsBytes(src));
} catch (JsonProcessingException e) {
return Optional.empty();
}
})
.filter(Optional::isPresent)
.forEach(src -> bulkRequestBuilder.add(new IndexRequest(indexName, indexName).source((byte[]) src.get())));
logger.debug("Executing bulk request with size {}", sources.size());
return bulkRequestBuilder.get();
}
示例9: 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();
}
}
示例10: bulkDelete
import org.elasticsearch.action.bulk.BulkRequestBuilder; //導入方法依賴的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);
}
}
示例11: 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
}
}
示例12: batchOperation
import org.elasticsearch.action.bulk.BulkRequestBuilder; //導入方法依賴的package包/類
@Override
protected void batchOperation(ConcurrentBiMap<Document, ActionRequest> oldBatch) throws Exception {
BulkRequestBuilder builder = getClient().prepareBulk();
for (ActionRequest request : oldBatch.values()) {
if (request instanceof UpdateRequest) {
builder.add((UpdateRequest) request);
} else if (request instanceof DeleteRequest) {
builder.add((DeleteRequest) request);
} else if (request instanceof IndexRequest) {
builder.add((IndexRequest) request);
} else {
throw new IllegalStateException("Should only have generated index, update and delete " +
"actions, but found" + request.getClass());
}
}
BulkResponse bulkResponse = builder.get();
if (bulkResponse.hasFailures()) {
throw new ESBulkFail();
} else {
for (Document doc : oldBatch.keySet()) {
log.info("Successfully sent {} to elastic", doc.getId());
}
}
}
示例13: bulkIndex
import org.elasticsearch.action.bulk.BulkRequestBuilder; //導入方法依賴的package包/類
@Override
public BulkResponse bulkIndex(Object... objects) {
BulkRequestBuilder bulkRequest = client.prepareBulk();
logger.debug("Bulk index {} objects", objects.length);
for (Object object : objects) {
if (object != null) {
if (object instanceof IndexRequestBuilder) {
bulkRequest.add((IndexRequestBuilder) object);
} else {
bulkRequest.add(getIndexRequest(object));
}
}
}
return bulkRequest.get();
}
示例14: testBulk
import org.elasticsearch.action.bulk.BulkRequestBuilder; //導入方法依賴的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
}
}
示例15: insertMultipleDocument
import org.elasticsearch.action.bulk.BulkRequestBuilder; //導入方法依賴的package包/類
/**
* This method insert the more than one Document at a time
*/
@Override
public void insertMultipleDocument() {
try {
client = ESclient.getInstant();
BulkRequestBuilder bulkDocument = client.prepareBulk();
// either use client#prepare, or use Requests# to directly build index/delete requests
bulkDocument.add(client.prepareIndex("school", "tenth", "1")
.setSource(jsonBuilder()
.startObject()
.field("name", "Sundar")
.field("age", "23")
.field("gender", "Male")
.endObject()
)
);
bulkDocument.add(client.prepareIndex("school", "tenth", "2")
.setSource(jsonBuilder()
.startObject()
.field("name", "Sundar S")
.field("age", "23")
.field("gender", "Male")
.endObject()
)
);
BulkResponse bulkResponse = bulkDocument.get();
if (bulkResponse.hasFailures()) {
// process failures by iterating through each bulk response item
} else {
log.info("All Documents inserted successfully...");
}
} catch (IOException ex) {
log.error("Exception occurred while get Multiple Document : " + ex, ex);
}
}