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


Java BulkRequestBuilder.add方法代码示例

本文整理汇总了Java中org.elasticsearch.action.bulk.BulkRequestBuilder.add方法的典型用法代码示例。如果您正苦于以下问题:Java BulkRequestBuilder.add方法的具体用法?Java BulkRequestBuilder.add怎么用?Java BulkRequestBuilder.add使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.elasticsearch.action.bulk.BulkRequestBuilder的用法示例。


在下文中一共展示了BulkRequestBuilder.add方法的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: 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

示例2: 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

示例3: 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

示例4: 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

示例5: 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,项目名称:database-transform-tool,代码行数:26,代码来源:ElasticsearchTransportFactory.java

示例6: doJob

import org.elasticsearch.action.bulk.BulkRequestBuilder; //导入方法依赖的package包/类
@Override
public void doJob(EventLog log, LogDto logDto, BulkRequestBuilder bulkRequest) {
    // 进行索引(for kibana),包含api调用、第三方调用、中间件调用
    if (this.getTypes().indexOf(log.getEventType()) != -1 && (log.getStatus().equals(EventLog.MONITOR_STATUS_FAILED) || log.getStatus().equals(EventLog.MONITOR_STATUS_SUCCESS))) {
        try {
            bulkRequest.add(transportClient.prepareIndex(this.esProperties.getIndex(), this.esProperties.getDoc())
                    .setSource(this.buildXContentBuilder(log, logDto)));
        } catch (IOException e) {
            LOGGER.error("构造一条es入库数据失败, {]", logDto);
        }
    }

    // 进行后续的处理
    if (null != this.getNextJob()) {
        this.getNextJob().doJob(log, logDto, bulkRequest);
    }
}
 
开发者ID:JThink,项目名称:SkyEye,代码行数:18,代码来源:Indexer.java

示例7: updateWithBulkTest

import org.elasticsearch.action.bulk.BulkRequestBuilder; //导入方法依赖的package包/类
@Test
public void updateWithBulkTest() throws IOException {
	BulkRequestBuilder request = client.prepareBulk();
	
	request.add(client.prepareUpdate(INDEX_NAME, TYPE_NAME, "AVQcXWKy50MnK8WFflRS")
						.setDoc(jsonBuilder()
								.startObject()
								.field("name", "testUpdateBulk")
								.endObject()
						)
				);
	request.add(client.prepareUpdate(INDEX_NAME, TYPE_NAME, "AVQcU5cD50MnK8WFflRQ")
						.setDoc(jsonBuilder()
								.startObject()
								.field("name", "testUpdateBulk2")
								.endObject()
						)
				);
	BulkResponse response = request.execute().actionGet();
	Assert.assertFalse(response.hasFailures());
}
 
开发者ID:walle-liao,项目名称:jaf-examples,代码行数:22,代码来源:DocumentTests.java

示例8: execute

import org.elasticsearch.action.bulk.BulkRequestBuilder; //导入方法依赖的package包/类
/**
 * Executes the list with requests as a bulk with maximum number of requests per bulk
 * @param requests
 * @param maxRequestsPerBulk
 * @return
 * @throws SQLException
 */
private int execute(List<?> requests, int maxRequestsPerBulk) throws SQLException{
	int result = 0;
	BulkRequestBuilder bulkReq = client.prepareBulk();
	for(Object req : requests){
		if(req instanceof IndexRequest)	bulkReq.add((IndexRequest)req);
		else if(req instanceof UpdateRequest) bulkReq.add((UpdateRequest)req);
		else if(req instanceof DeleteRequest) bulkReq.add((DeleteRequest)req);
		else if(req instanceof IndexRequestBuilder) bulkReq.add((IndexRequestBuilder)req);
		else if(req instanceof UpdateRequestBuilder) bulkReq.add((UpdateRequestBuilder)req);
		else if(req instanceof DeleteRequestBuilder) bulkReq.add((DeleteRequestBuilder)req);
		else throw new SQLException("Type "+req.getClass()+" cannot be added to a bulk request");
		
		if(bulkReq.numberOfActions() > maxRequestsPerBulk){
			result += bulkReq.get().getItems().length;
			bulkReq = client.prepareBulk();
		}
	}
	
	if(bulkReq.numberOfActions() > 0){
		result += bulkReq.get().getItems().length;
	}
	return result;
}
 
开发者ID:Anchormen,项目名称:sql4es,代码行数:31,代码来源:ESUpdateState.java

示例9: writeDependencyLinks

import org.elasticsearch.action.bulk.BulkRequestBuilder; //导入方法依赖的package包/类
@VisibleForTesting void writeDependencyLinks(List<DependencyLink> links, long timestampMillis) {
  long midnight = Util.midnightUTC(timestampMillis);
  TransportClient client = ((NativeClient) storage.client()).client;
  BulkRequestBuilder request = client.prepareBulk();
  for (DependencyLink link : links) {
    request.add(client.prepareIndex(
        storage.indexNameFormatter.indexNameForTimestamp(midnight),
        ElasticsearchConstants.DEPENDENCY_LINK)
        .setId(link.parent + "|" + link.child) // Unique constraint
        .setSource(
            "parent", link.parent,
            "child", link.child,
            "callCount", link.callCount));
  }
  request.execute().actionGet();
  client.admin().indices().flush(new FlushRequest()).actionGet();
}
 
开发者ID:liaominghua,项目名称:zipkin,代码行数:18,代码来源:ElasticsearchDependenciesTest.java

示例10: insert

import org.elasticsearch.action.bulk.BulkRequestBuilder; //导入方法依赖的package包/类
@Override
public void insert(List<BucketOwner> bucketOwners, Date collectionTime) {
	
	if (bucketOwners != null && !bucketOwners.isEmpty()) {
		BulkRequestBuilder requestBuilder = elasticClient.prepareBulk();
		// Generate JSON for object buckets info
		for (BucketOwner bucketOwner : bucketOwners) {
			XContentBuilder objectBucketBuilder = toJsonFormat(bucketOwner, collectionTime);
			IndexRequestBuilder request = elasticClient.prepareIndex().setIndex(bucketownerIndexDayName)
					.setType(BUCKET_OWNER_INDEX_TYPE).setSource(objectBucketBuilder);
			requestBuilder.add(request);
		}

		BulkResponse bulkResponse = requestBuilder.execute().actionGet();
		int items = bulkResponse.getItems().length;
		LOGGER.info("Took " + bulkResponse.getTookInMillis() + " ms to index [" + items + "] items in ElasticSearch"
				+ "index: " + bucketownerIndexDayName + " index type: " + BUCKET_OWNER_INDEX_TYPE);

		if (bulkResponse.hasFailures()) {
			LOGGER.error("Failures occured while items in ElasticSearch " + "index: " + bucketownerIndexDayName
					+ " index type: " + BUCKET_OWNER_INDEX_TYPE);
		}
	}
}
 
开发者ID:carone1,项目名称:ecs-dashboard,代码行数:25,代码来源:ElasticBucketOwnerDAO.java

示例11: deleteAllIds

import org.elasticsearch.action.bulk.BulkRequestBuilder; //导入方法依赖的package包/类
@Override
public List<String> deleteAllIds(final Collection<String> ids) {
  if (ids.isEmpty()) {
    return ImmutableList.of();
  }

  final BulkRequestBuilder bulk = client
    .prepareBulk()
    .setRefreshPolicy(policy.get());

  for (final String id : ids) {
    bulk.add(client.prepareDelete(index, type, id));
  }

  final BulkResponse response = bulk.execute().actionGet();

  final ImmutableList.Builder<String> builder = ImmutableList.builder();
  for (final BulkItemResponse item : response.getItems()) {
    builder.add(item.getId());
  }
  return builder.build();
}
 
开发者ID:jloisel,项目名称:elastic-crud,代码行数:23,代码来源:ElasticSearchRepository.java

示例12: before

import org.elasticsearch.action.bulk.BulkRequestBuilder; //导入方法依赖的package包/类
@Before
public void before() throws IOException {
  if(!client.admin().indices().prepareExists(INDEX).execute().actionGet().isExists()) {
    client.admin().indices().prepareCreate(INDEX).execute().actionGet();
  }
  final JsonSerializer<Person> serializer = mapper.serializer(Person.class);
  final BulkRequestBuilder bulk = client.prepareBulk();
  for (int i = 0; i < SIZE; i++) {

    final String name = UUID.randomUUID().toString();
    final IndexRequest request = new IndexRequest(INDEX, TYPE);
    request.source(serializer.apply(Person.builder().id("").firstname(name).lastname(name).build()), JSON);
    bulk.add(request);
  }

  client.bulk(bulk.request()).actionGet();
  flush(INDEX);
}
 
开发者ID:jloisel,项目名称:elastic-crud,代码行数:19,代码来源:ElasticScrollingFactoryEsTest.java

示例13: before

import org.elasticsearch.action.bulk.BulkRequestBuilder; //导入方法依赖的package包/类
@Before
public void before() throws IOException {
  if(!client.admin().indices().prepareExists(INDEX).execute().actionGet().isExists()) {
    client.admin().indices().prepareCreate(INDEX).execute().actionGet();
  }
  final BulkRequestBuilder bulk = client.prepareBulk();
  final JsonSerializer<Person> serializer = mapper.serializer(Person.class);
  for (int i = 0; i < SIZE; i++) {

    final String name = UUID.randomUUID().toString();
    final IndexRequest request = new IndexRequest(INDEX, TYPE);
    request.source(serializer.apply(Person.builder().id("").firstname(name).lastname(name).build()), JSON);
    bulk.add(request);
  }

  client.bulk(bulk.request()).actionGet();
  flush(INDEX);
}
 
开发者ID:jloisel,项目名称:elastic-crud,代码行数:19,代码来源:BulkDeleteEsTest.java

示例14: 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);
    }
}
 
开发者ID:neowu,项目名称:core-ng-project,代码行数:25,代码来源:ElasticSearchTypeImpl.java

示例15: 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
	}
}
 
开发者ID:dstl,项目名称:baleen,代码行数:18,代码来源:ElasticsearchTestBase.java


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