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


Java BulkRequestBuilder类代码示例

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

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

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

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

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

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

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

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

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

示例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;
}
 
开发者ID:Biacode,项目名称:escommons,代码行数:17,代码来源:AbstractEsRepository.java

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


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

示例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;
}
 
开发者ID:codelibs,项目名称:elasticsearch-indexing-proxy,代码行数:25,代码来源:RequestUtils.java

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

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

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

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


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