当前位置: 首页>>代码示例>>Java>>正文


Java BulkResponse类代码示例

本文整理汇总了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());
	}

}
 
开发者ID:judasn,项目名称:Elasticsearch-Tutorial-zh-CN,代码行数:23,代码来源:BaseDemo.java

示例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());
}
 
开发者ID:Erudika,项目名称:para-search-elasticsearch,代码行数:21,代码来源:ElasticSearch.java

示例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());
}
 
开发者ID:Erudika,项目名称:para-search-elasticsearch,代码行数:20,代码来源:ElasticSearch.java

示例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;
}
 
开发者ID:dev-share,项目名称:database-transform-tool,代码行数:19,代码来源:ElasticsearchTransportFactory.java

示例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());
        }
    }
}
 
开发者ID:apache,项目名称:incubator-skywalking,代码行数:21,代码来源:BatchEsDAO.java

示例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);
        }
    });
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:21,代码来源:AbstractAsyncBulkByScrollAction.java

示例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());
}
 
开发者ID:justor,项目名称:elasticsearch_my,代码行数:24,代码来源:DynamicMappingDisabledTests.java

示例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;
}
 
开发者ID:dev-share,项目名称:css-elasticsearch,代码行数:18,代码来源:ElasticsearchHighRestFactory.java

示例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;
}
 
开发者ID:dev-share,项目名称:css-elasticsearch,代码行数:26,代码来源:ElasticsearchTransportFactory.java

示例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();


    }
 
开发者ID:hs-web,项目名称:hsweb-learning,代码行数:25,代码来源:ElasticSearch.java

示例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);
}
 
开发者ID:pinterest,项目名称:soundwave,代码行数:27,代码来源:EsStore.java

示例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());
	}
}
 
开发者ID:judasn,项目名称:Elasticsearch-Tutorial-zh-CN,代码行数:37,代码来源:BaseDemo.java

示例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");
  }
}
 
开发者ID:MoneZhao,项目名称:elasticsearch,代码行数:26,代码来源:App.java

示例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());
    }
}
 
开发者ID:uavorg,项目名称:uavstack,代码行数:23,代码来源:ThreadAnalysisCollectDataHandler.java

示例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 + " 条记录==========================");
    }
}
 
开发者ID:wxz1211,项目名称:dooo,代码行数:28,代码来源:IndexManager.java


注:本文中的org.elasticsearch.action.bulk.BulkResponse类示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。