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


Java BulkRequestBuilder.get方法代码示例

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


在下文中一共展示了BulkRequestBuilder.get方法的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: 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

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

示例4: createIndex

import org.elasticsearch.action.bulk.BulkRequestBuilder; //导入方法依赖的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

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

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

示例7: dropClass

import org.elasticsearch.action.bulk.BulkRequestBuilder; //导入方法依赖的package包/类
public void dropClass(final String className) {
  SearchResponse scrollResponse = esClient.getClient().prepareSearch(getIndexName()).setTypes(className)
      .setSearchType(SearchType.SCAN).setScroll(new TimeValue(60000)).setQuery(QueryBuilders.matchAllQuery()).setSize(100).get();
  final BulkRequestBuilder bulkRequestBuilder = esClient.getClient().prepareBulk().setRefresh(true);
  while (true) {
    if (scrollResponse.getHits().getHits().length == 0) {
      break;
    }

    for (SearchHit hit : scrollResponse.getHits().getHits()) {
      bulkRequestBuilder.add(esClient.getClient().prepareDelete(getIndexName(), className, hit.getId()));
    }

    scrollResponse = esClient.getClient().prepareSearchScroll(scrollResponse.getScrollId()).setScroll(new TimeValue(60000)).get();
  }
  if (bulkRequestBuilder.numberOfActions() > 0) {
    bulkRequestBuilder.get();
  }
}
 
开发者ID:orientechnologies,项目名称:orientdb-elasticsearch,代码行数:20,代码来源:OElasticSearchDatabaseSync.java

示例8: bulkIndex

import org.elasticsearch.action.bulk.BulkRequestBuilder; //导入方法依赖的package包/类
public <T> BulkResponse bulkIndex(String indexName, List<T> sources) {
    BulkRequestBuilder bulkRequestBuilder = client.prepareBulk();

    sources
            .parallelStream()
            .map(src -> {
                try {
                    return Optional.of(objectMapper.writeValueAsBytes(src));
                } catch (JsonProcessingException e) {
                    return Optional.empty();
                }
            })
            .filter(Optional::isPresent)
            .forEach(src -> bulkRequestBuilder.add(new IndexRequest(indexName, indexName).source((byte[]) src.get())));

    logger.debug("Executing bulk request with size {}", sources.size());

    return bulkRequestBuilder.get();
}
 
开发者ID:luminis-ams,项目名称:elasticsearch-performance,代码行数:20,代码来源:Elasticsearch.java

示例9: run

import org.elasticsearch.action.bulk.BulkRequestBuilder; //导入方法依赖的package包/类
@Override
public void run() {
    SearchResponse searchResponse = client.prepareSearch(searchIndex)
            .setTypes("Document")
            .setQuery(QueryBuilders.boolQuery()
                    .mustNot(QueryBuilders.hasChildQuery("DocumentInSystem", QueryBuilders.matchAllQuery())))
            .setSize(9999)
            .get();

    BulkRequestBuilder bulkRequestBuilder = client.prepareBulk();
    for (SearchHit searchHit : searchResponse.getHits().hits()) {
        DeleteRequestBuilder delete = client.prepareDelete(searchIndex, "Document", searchHit.getId());
        bulkRequestBuilder.add(delete);
    }

    if (bulkRequestBuilder.numberOfActions() > 0) {
        bulkRequestBuilder.get();
    }
}
 
开发者ID:nlpie,项目名称:nlptab,代码行数:20,代码来源:DeleteOrphanedDocuments.java

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

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

示例12: batchOperation

import org.elasticsearch.action.bulk.BulkRequestBuilder; //导入方法依赖的package包/类
@Override
protected void batchOperation(ConcurrentBiMap<Document, ActionRequest> oldBatch) throws Exception {
  BulkRequestBuilder builder = getClient().prepareBulk();
  for (ActionRequest request : oldBatch.values()) {
    if (request instanceof UpdateRequest) {
      builder.add((UpdateRequest) request);
    } else if (request instanceof DeleteRequest) {
      builder.add((DeleteRequest) request);
    } else if (request instanceof IndexRequest) {
      builder.add((IndexRequest) request);
    } else {
      throw new IllegalStateException("Should only have generated index, update and delete " +
          "actions, but found" + request.getClass());
    }
  }
  BulkResponse bulkResponse = builder.get();
  if (bulkResponse.hasFailures()) {
    throw new ESBulkFail();
  } else {
    for (Document doc : oldBatch.keySet()) {
      log.info("Successfully sent {} to elastic", doc.getId());
    }
  }
}
 
开发者ID:nsoft,项目名称:jesterj,代码行数:25,代码来源:ElasticSender.java

示例13: bulkIndex

import org.elasticsearch.action.bulk.BulkRequestBuilder; //导入方法依赖的package包/类
@Override
public BulkResponse bulkIndex(Object... objects) {
    BulkRequestBuilder bulkRequest = client.prepareBulk();
    logger.debug("Bulk index {} objects", objects.length);
    for (Object object : objects) {
        if (object != null) {
            if (object instanceof IndexRequestBuilder) {
                bulkRequest.add((IndexRequestBuilder) object);
            } else {
                bulkRequest.add(getIndexRequest(object));
            }
        }
    }
    return bulkRequest.get();

}
 
开发者ID:kzwang,项目名称:elasticsearch-osem,代码行数:17,代码来源:ElasticSearchIndexerImpl.java

示例14: testBulk

import org.elasticsearch.action.bulk.BulkRequestBuilder; //导入方法依赖的package包/类
@Test
public void testBulk() throws Exception {
    BulkRequestBuilder bulkRequest = client.prepareBulk();

    // either use client#prepare, or use Requests# to directly build
    // index/delete requests
    bulkRequest.add(client.prepareIndex("twitter", "tweet", "1").setSource(XContentFactory.jsonBuilder().startObject().field("user", "kimchy")
            .field("postDate", new Date()).field("message", "trying out Elasticsearch").endObject()));

    bulkRequest.add(client.prepareIndex("twitter", "tweet", "2").setSource(XContentFactory.jsonBuilder().startObject().field("user", "kimchy")
            .field("postDate", new Date()).field("message", "another post").endObject()));

    BulkResponse bulkResponse = bulkRequest.get();
    if (bulkResponse.hasFailures()) {
        // process failures by iterating through each bulk response item
    }
}
 
开发者ID:dzh,项目名称:jframe,代码行数:18,代码来源:TestTransportClient.java

示例15: insertMultipleDocument

import org.elasticsearch.action.bulk.BulkRequestBuilder; //导入方法依赖的package包/类
/**
 * This method insert the more than one Document at a time
 */
@Override
public void insertMultipleDocument() {
    try {
        client = ESclient.getInstant();
        BulkRequestBuilder bulkDocument = client.prepareBulk();

        // either use client#prepare, or use Requests# to directly build index/delete requests
        bulkDocument.add(client.prepareIndex("school", "tenth", "1")
                .setSource(jsonBuilder()
                        .startObject()
                        .field("name", "Sundar")
                        .field("age", "23")
                        .field("gender", "Male")
                        .endObject()
                )
        );

        bulkDocument.add(client.prepareIndex("school", "tenth", "2")
                .setSource(jsonBuilder()
                        .startObject()
                        .field("name", "Sundar S")
                        .field("age", "23")
                        .field("gender", "Male")
                        .endObject()
                )
        );
        BulkResponse bulkResponse = bulkDocument.get();
        if (bulkResponse.hasFailures()) {
            // process failures by iterating through each bulk response item
        } else {
            log.info("All Documents inserted successfully...");
        }

    } catch (IOException ex) {
        log.error("Exception occurred while get Multiple Document : " + ex, ex);
    }
}
 
开发者ID:sundarcse1216,项目名称:es-crud,代码行数:41,代码来源:ElasticSearchCrudImpl.java


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