本文整理匯總了Java中org.elasticsearch.action.bulk.BulkRequestBuilder類的典型用法代碼示例。如果您正苦於以下問題:Java BulkRequestBuilder類的具體用法?Java BulkRequestBuilder怎麽用?Java BulkRequestBuilder使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
BulkRequestBuilder類屬於org.elasticsearch.action.bulk包,在下文中一共展示了BulkRequestBuilder類的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: 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());
}
示例3: 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());
}
示例4: bulkDelete
import org.elasticsearch.action.bulk.BulkRequestBuilder; //導入依賴的package包/類
@Override
public String bulkDelete(String index, String type, String... ids) {
try {
if(client==null){
init();
}
BulkRequestBuilder bulkRequest = client.prepareBulk();
for (String id : ids) {
bulkRequest.add(client.prepareDelete(index, type, id));
}
BulkResponse result = bulkRequest.execute().get();
return result.toString();
}catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
示例5: pushSpanToBulkRequest
import org.elasticsearch.action.bulk.BulkRequestBuilder; //導入依賴的package包/類
/**
* 存儲到ES
*
* @param appUUID
* @param span
* @param bulkRequest
*/
private void pushSpanToBulkRequest(String appUUID, String appGroup, Span span, BulkRequestBuilder bulkRequest) {
/**
* 保證不會重複
*/
String uuid = EncodeHelper.encodeMD5(span.toString());
/**
* 獲取當前正在使用的index名稱
*/
String currentIndex = indexMgr.prepareIndex();
IndexRequestBuilder irb = client.getClient().prepareIndex(currentIndex, InvokeChainIndexMgr.IVC_Table, uuid);
Map<String, Object> m = span.toMap();
m.put("appuuid", appUUID);
m.put("appgroup", appGroup);
irb.setSource(m);
bulkRequest.add(irb);
}
示例6: batchPersistence
import org.elasticsearch.action.bulk.BulkRequestBuilder; //導入依賴的package包/類
@Override public void batchPersistence(List<?> batchCollection) {
BulkRequestBuilder bulkRequest = getClient().prepareBulk();
logger.debug("bulk data size: {}", batchCollection.size());
if (CollectionUtils.isNotEmpty(batchCollection)) {
batchCollection.forEach(builder -> {
if (builder instanceof IndexRequestBuilder) {
bulkRequest.add((IndexRequestBuilder)builder);
}
if (builder instanceof UpdateRequestBuilder) {
bulkRequest.add((UpdateRequestBuilder)builder);
}
});
BulkResponse bulkResponse = bulkRequest.execute().actionGet();
if (bulkResponse.hasFailures()) {
logger.error(bulkResponse.buildFailureMessage());
}
}
}
示例7: testBulk
import org.elasticsearch.action.bulk.BulkRequestBuilder; //導入依賴的package包/類
public void testBulk() {
// Index by bulk with RefreshPolicy.WAIT_UNTIL
BulkRequestBuilder bulk = client().prepareBulk().setRefreshPolicy(RefreshPolicy.WAIT_UNTIL);
bulk.add(client().prepareIndex("test", "test", "1").setSource("foo", "bar"));
assertBulkSuccess(bulk.get());
assertSearchHits(client().prepareSearch("test").setQuery(matchQuery("foo", "bar")).get(), "1");
// Update by bulk with RefreshPolicy.WAIT_UNTIL
bulk = client().prepareBulk().setRefreshPolicy(RefreshPolicy.WAIT_UNTIL);
bulk.add(client().prepareUpdate("test", "test", "1").setDoc(Requests.INDEX_CONTENT_TYPE, "foo", "baz"));
assertBulkSuccess(bulk.get());
assertSearchHits(client().prepareSearch("test").setQuery(matchQuery("foo", "baz")).get(), "1");
// Delete by bulk with RefreshPolicy.WAIT_UNTIL
bulk = client().prepareBulk().setRefreshPolicy(RefreshPolicy.WAIT_UNTIL);
bulk.add(client().prepareDelete("test", "test", "1"));
assertBulkSuccess(bulk.get());
assertNoSearchHits(client().prepareSearch("test").setQuery(matchQuery("foo", "bar")).get());
// Update makes a noop
bulk = client().prepareBulk().setRefreshPolicy(RefreshPolicy.WAIT_UNTIL);
bulk.add(client().prepareDelete("test", "test", "1"));
assertBulkSuccess(bulk.get());
}
示例8: bulkUpsert
import org.elasticsearch.action.bulk.BulkRequestBuilder; //導入依賴的package包/類
public String bulkUpsert(String index,String type,List<Object> jsons){
try {
if(client==null){
init();
}
BulkRequestBuilder bulkRequest = client.prepareBulk();
for (Object json : jsons) {
JSONObject obj = JSON.parseObject(JSON.toJSONString(json));
String id = UUIDs.base64UUID();
if(obj.containsKey("id")){
id = obj.getString("id");
obj.remove("id");
bulkRequest.add(client.prepareUpdate(index, type, id).setDoc(obj.toJSONString(),XContentType.JSON));
}else{
bulkRequest.add(client.prepareIndex(index, type, id).setSource(obj.toJSONString(),XContentType.JSON));
}
}
BulkResponse result = bulkRequest.execute().get();
return result.toString();
}catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
示例9: 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;
}
示例10: BulkIndex
import org.elasticsearch.action.bulk.BulkRequestBuilder; //導入依賴的package包/類
private static void BulkIndex(Client client) throws IOException {
BulkRequestBuilder requestBuilder = client.prepareBulk();
requestBuilder.add(client.prepareIndex("twitter","tweet","4")
.setSource(jsonBuilder()
.startObject()
.field("user","niekaijie")
.field("school","beiyou")
.field("address","haidianqu")
.endObject())
);
requestBuilder.add(client.prepareIndex("twitter","tweet","3")
.setSource(jsonBuilder()
.startObject()
.field("user","林誌穎aa")
.field("school","台灣大學")
.field("address","台灣")
.endObject())
);
BulkResponse response = requestBuilder.get();
}
示例11: createBulkRequest
import org.elasticsearch.action.bulk.BulkRequestBuilder; //導入依賴的package包/類
public static BulkRequestBuilder createBulkRequest(final Client client, final StreamInput streamInput, final String index)
throws IOException {
final BulkRequestBuilder builder = client.prepareBulk();
final BulkRequest request = builder.request();
request.readFrom(streamInput);
if (index != null) {
request.requests().stream().forEach(req -> {
if (req instanceof DeleteRequest) {
((DeleteRequest) req).index(index);
} else if (req instanceof DeleteByQueryRequest) {
((DeleteByQueryRequest) req).indices(index);
} else if (req instanceof IndexRequest) {
((IndexRequest) req).index(index);
} else if (req instanceof UpdateRequest) {
((UpdateRequest) req).index(index);
} else if (req instanceof UpdateByQueryRequest) {
((UpdateByQueryRequest) req).indices(index);
} else {
throw new ElasticsearchException("Unsupported request in bulk: " + req);
}
});
}
return builder;
}
示例12: 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());
}
}
示例13: 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");
}
}
示例14: 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());
}
}
示例15: pushDataToBulkRequest
import org.elasticsearch.action.bulk.BulkRequestBuilder; //導入依賴的package包/類
/**
*
* @param appUUID
* @param appGroup
* @param span
* @param bulkRequest
*/
private void pushDataToBulkRequest(JavaThreadObject jto, BulkRequestBuilder bulkRequest) {
/**
* 保證不會重複
*/
String uuid = EncodeHelper.encodeMD5(jto.toString());
/**
* 獲取當前正在使用的index名稱
*/
String currentIndex = indexMgr.prepareIndex();
IndexRequestBuilder irb = client.getClient().prepareIndex(currentIndex, ThreadAnalysisIndexMgr.JTA_TABLE, uuid);
Map<String, Object> m = jto.toMap();
irb.setSource(m);
bulkRequest.add(irb);
}