本文整理匯總了Java中org.elasticsearch.action.bulk.BulkResponse類的典型用法代碼示例。如果您正苦於以下問題:Java BulkResponse類的具體用法?Java BulkResponse怎麽用?Java BulkResponse使用的例子?那麽, 這裏精選的類代碼示例或許可以為您提供幫助。
BulkResponse類屬於org.elasticsearch.action.bulk包,在下文中一共展示了BulkResponse類的15個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。
示例1: batchDelete
import org.elasticsearch.action.bulk.BulkResponse; //導入依賴的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.BulkResponse; //導入依賴的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.BulkResponse; //導入依賴的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.BulkResponse; //導入依賴的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: batchPersistence
import org.elasticsearch.action.bulk.BulkResponse; //導入依賴的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());
}
}
}
示例6: sendBulkRequest
import org.elasticsearch.action.bulk.BulkResponse; //導入依賴的package包/類
/**
* Send a bulk request, handling retries.
*/
void sendBulkRequest(TimeValue thisBatchStartTime, BulkRequest request) {
if (task.isCancelled()) {
finishHim(null);
return;
}
bulkRetry.withAsyncBackoff(client, request, new ActionListener<BulkResponse>() {
@Override
public void onResponse(BulkResponse response) {
onBulkResponse(thisBatchStartTime, response);
}
@Override
public void onFailure(Exception e) {
finishHim(e);
}
});
}
示例7: testDynamicDisabled
import org.elasticsearch.action.bulk.BulkResponse; //導入依賴的package包/類
public void testDynamicDisabled() {
IndexRequest request = new IndexRequest("index", "type", "1");
request.source(Requests.INDEX_CONTENT_TYPE, "foo", 3);
BulkRequest bulkRequest = new BulkRequest();
bulkRequest.add(request);
final AtomicBoolean onFailureCalled = new AtomicBoolean();
transportBulkAction.execute(bulkRequest, new ActionListener<BulkResponse>() {
@Override
public void onResponse(BulkResponse bulkResponse) {
fail("onResponse shouldn't be called");
}
@Override
public void onFailure(Exception e) {
onFailureCalled.set(true);
assertThat(e, instanceOf(IndexNotFoundException.class));
assertEquals("no such index and [index.mapper.dynamic] is [false]", e.getMessage());
}
});
assertTrue(onFailureCalled.get());
}
示例8: bulkDelete
import org.elasticsearch.action.bulk.BulkResponse; //導入依賴的package包/類
public String bulkDelete(String index,String type,String... ids){
try {
if(xclient==null){
init();
}
BulkRequest request = new BulkRequest();
for (String id : ids) {
request.add(new DeleteRequest(index, type, id));
}
BulkResponse result = xclient.bulk(request);
return result.toString();
}catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return null;
}
示例9: bulkUpsert
import org.elasticsearch.action.bulk.BulkResponse; //導入依賴的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;
}
示例10: BulkIndex
import org.elasticsearch.action.bulk.BulkResponse; //導入依賴的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: bulkInsert
import org.elasticsearch.action.bulk.BulkResponse; //導入依賴的package包/類
protected <E extends EsDocument> EsBulkResponseSummary bulkInsert(List<E> insertDoc,
int batchSize,
ObjectMapper mapper)
throws Exception {
Preconditions.checkArgument(batchSize > 0);
List<BulkResponse> responses = new ArrayList<>();
int count = 0;
BulkRequestExecutor executor = new BulkRequestExecutor(this.esClient);
for (E doc : insertDoc) {
executor
.add(new IndexRequest(getIndexName(), getDocTypeName())
.source(mapper.writeValueAsBytes(doc)).id(doc.getId()));
count++;
if (count >= batchSize) {
responses.add(executor.execute());
count = 0;
executor = new BulkRequestExecutor(this.esClient);
}
}
if (count > 0) {
responses.add(executor.execute());
}
return new EsBulkResponseSummary(responses);
}
示例12: batchUpdate
import org.elasticsearch.action.bulk.BulkResponse; //導入依賴的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.BulkResponse; //導入依賴的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.BulkResponse; //導入依賴的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: createIndex
import org.elasticsearch.action.bulk.BulkResponse; //導入依賴的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 + " 條記錄==========================");
}
}