Java Code Examples for org.elasticsearch.index.reindex.BulkByScrollResponse#getUpdated()

The following examples show how to use org.elasticsearch.index.reindex.BulkByScrollResponse#getUpdated() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: EsHighLevelRestTest1.java    From java-study with Apache License 2.0 5 votes vote down vote up
/**
	 * 根据查询条件删除
	 *
	 * @throws IOException
	 */
	private static void deleteByQuery() throws IOException {
		String type = "_doc";
		String index = "test1";
		DeleteByQueryRequest request = new DeleteByQueryRequest(index,type);
		// 设置查询条件
		request.setQuery(QueryBuilders.termQuery("uid",1234));
		// 同步执行
		BulkByScrollResponse bulkResponse = client.deleteByQuery(request, RequestOptions.DEFAULT);

		// 异步执行
//		client.updateByQueryAsync(request, RequestOptions.DEFAULT, listener);

		// 返回结果
		TimeValue timeTaken = bulkResponse.getTook();
		boolean timedOut = bulkResponse.isTimedOut();
		long totalDocs = bulkResponse.getTotal();
		long updatedDocs = bulkResponse.getUpdated();
		long deletedDocs = bulkResponse.getDeleted();
		long batches = bulkResponse.getBatches();
		long noops = bulkResponse.getNoops();
		long versionConflicts = bulkResponse.getVersionConflicts();
		long bulkRetries = bulkResponse.getBulkRetries();
		long searchRetries = bulkResponse.getSearchRetries();
		TimeValue throttledMillis = bulkResponse.getStatus().getThrottled();
		TimeValue throttledUntilMillis = bulkResponse.getStatus().getThrottledUntil();
		List<ScrollableHitSource.SearchFailure> searchFailures = bulkResponse.getSearchFailures();
		List<BulkItemResponse.Failure> bulkFailures = bulkResponse.getBulkFailures();
		System.out.println("查询更新总共花费了:" + timeTaken.getMillis() + " 毫秒,总条数:" + totalDocs + ",更新数:" + updatedDocs);

	}
 
Example 2
Source File: ElasticsearchIndexer.java    From datashare with GNU Affero General Public License v3.0 5 votes vote down vote up
private boolean groupTagUntag(Project prj, List<String> documentIds, Script untagScript) throws IOException {
    UpdateByQueryRequest updateByQuery = new UpdateByQueryRequest(prj.getId());
    updateByQuery.setQuery(termsQuery("_id", documentIds.toArray(new String[0])));
    updateByQuery.setConflicts("proceed");
    updateByQuery.setScript(untagScript);
    updateByQuery.setRefresh(esCfg.refreshPolicy.getValue().equals("true"));
    BulkByScrollResponse updateResponse = client.updateByQuery(updateByQuery, RequestOptions.DEFAULT);
    return updateResponse.getBulkFailures().size() == 0 && updateResponse.getUpdated() > 0 ;
}
 
Example 3
Source File: EsHighLevelRestTest2.java    From java-study with Apache License 2.0 4 votes vote down vote up
/**
	 * 索引复制
	 * 
	 * @throws IOException
	 */
	private static void reindex() throws IOException {
		// 创建索引复制请求并进行索引复制
		ReindexRequest request = new ReindexRequest();
		// 需要复制的索引
		request.setSourceIndices("user");
		// 复制的目标索引
		request.setDestIndex("dest_test");

		// 表示如果在复制索引的时候有缺失的文档的话会进行创建,默认是index
		request.setDestOpType("create");
		// 如果在复制的过程中发现版本冲突,那么会继续进行复制
		request.setConflicts("proceed");

		// 只复制文档类型为 userindex 的数据
		request.setSourceDocTypes("userindex");
		// 只复制 pancm 用户的数据
		request.setSourceQuery(new TermQueryBuilder("user", "pancm"));
		// 设置复制文档的数量
		request.setSize(10);
		// 设置一次批量处理的条数,默认是1000
		request.setSourceBatchSize(100);

		// 进行排序
//		request.addSortField("postDate", SortOrder.DESC);

		// 指定切片大小
		request.setSlices(2);
		
		//设置超时时间
		request.setTimeout(TimeValue.timeValueMinutes(2));
		//允许刷新
		request.setRefresh(true);
		
		// 同步执行
		BulkByScrollResponse bulkResponse = client.reindex(request, RequestOptions.DEFAULT);

		// 异步执行
//		client.reindexAsync(request, RequestOptions.DEFAULT, listener);

		// 响应结果处理

		TimeValue timeTaken = bulkResponse.getTook();
		boolean timedOut = bulkResponse.isTimedOut();
		long totalDocs = bulkResponse.getTotal();
		long updatedDocs = bulkResponse.getUpdated();
		long createdDocs = bulkResponse.getCreated();
		long deletedDocs = bulkResponse.getDeleted();
		long batches = bulkResponse.getBatches();
		long noops = bulkResponse.getNoops();
		long versionConflicts = bulkResponse.getVersionConflicts();
		long bulkRetries = bulkResponse.getBulkRetries();
		long searchRetries = bulkResponse.getSearchRetries();
		TimeValue throttledMillis = bulkResponse.getStatus().getThrottled();
		TimeValue throttledUntilMillis = bulkResponse.getStatus().getThrottledUntil();
		List<ScrollableHitSource.SearchFailure> searchFailures = bulkResponse.getSearchFailures();
		List<BulkItemResponse.Failure> bulkFailures = bulkResponse.getBulkFailures();

		System.out.println("索引复制总共花费了:" + timeTaken.getMillis() + " 毫秒,总条数:" + totalDocs + ",创建数:" + createdDocs
				+ ",更新数:" + updatedDocs);
	}
 
Example 4
Source File: EsHighLevelRestTest1.java    From java-study with Apache License 2.0 3 votes vote down vote up
/**
	 * 根据查询条件更新
	 *
	 * @throws IOException
	 */
	private static void updateByQuery() throws IOException {
		String type = "_doc";
		String index = "test1";
		//
		UpdateByQueryRequest request = new UpdateByQueryRequest(index,type);
		// 设置查询条件
		request.setQuery(new TermQueryBuilder("user", "pancm"));
		BoolQueryBuilder boolQueryBuilder = new BoolQueryBuilder();

		// 设置复制文档的数量
		request.setSize(10);
		// 设置一次批量处理的条数,默认是1000
		request.setBatchSize(100);
		//设置超时时间
		request.setTimeout(TimeValue.timeValueMinutes(2));
		//索引选项
		request.setIndicesOptions(IndicesOptions.LENIENT_EXPAND_OPEN);

		// 同步执行
		BulkByScrollResponse bulkResponse = client.updateByQuery(request, RequestOptions.DEFAULT);

		// 异步执行
//		client.updateByQueryAsync(request, RequestOptions.DEFAULT, listener);

		// 返回结果
		TimeValue timeTaken = bulkResponse.getTook();
		boolean timedOut = bulkResponse.isTimedOut();
		long totalDocs = bulkResponse.getTotal();
		long updatedDocs = bulkResponse.getUpdated();
		long deletedDocs = bulkResponse.getDeleted();
		long batches = bulkResponse.getBatches();
		long noops = bulkResponse.getNoops();
		long versionConflicts = bulkResponse.getVersionConflicts();
		long bulkRetries = bulkResponse.getBulkRetries();
		long searchRetries = bulkResponse.getSearchRetries();
		TimeValue throttledMillis = bulkResponse.getStatus().getThrottled();
		TimeValue throttledUntilMillis = bulkResponse.getStatus().getThrottledUntil();
		List<ScrollableHitSource.SearchFailure> searchFailures = bulkResponse.getSearchFailures();
		List<BulkItemResponse.Failure> bulkFailures = bulkResponse.getBulkFailures();
		System.out.println("查询更新总共花费了:" + timeTaken.getMillis() + " 毫秒,总条数:" + totalDocs + ",更新数:" + updatedDocs);

	}