當前位置: 首頁>>代碼示例>>Java>>正文


Java SearchResponse.getScrollId方法代碼示例

本文整理匯總了Java中org.elasticsearch.action.search.SearchResponse.getScrollId方法的典型用法代碼示例。如果您正苦於以下問題:Java SearchResponse.getScrollId方法的具體用法?Java SearchResponse.getScrollId怎麽用?Java SearchResponse.getScrollId使用的例子?那麽, 這裏精選的方法代碼示例或許可以為您提供幫助。您也可以進一步了解該方法所在org.elasticsearch.action.search.SearchResponse的用法示例。


在下文中一共展示了SearchResponse.getScrollId方法的7個代碼示例,這些例子默認根據受歡迎程度排序。您可以為喜歡或者感覺有用的代碼點讚,您的評價將有助於係統推薦出更棒的Java代碼示例。

示例1: iterator

import org.elasticsearch.action.search.SearchResponse; //導入方法依賴的package包/類
@Override
public Iterator<T> iterator() {
    init();
    if (firstResponse == null) {
        return new ArrayList<T>().iterator();
    }

    SearchResponse response;
    Iterator<T> it;
    if (firstCall) {
        response = firstResponse;
        it = firstIterable.iterator();
        firstCall = false;
    } else {
        response = getInitialSearchResponse();
        it = searchResponseToIterable(response).iterator();
    }
    String scrollId = response.getScrollId();
    return new InfiniteIterator(scrollId, it);
}
 
開發者ID:mware-solutions,項目名稱:memory-graph,代碼行數:21,代碼來源:InfiniteScrollIterable.java

示例2: wrap

import org.elasticsearch.action.search.SearchResponse; //導入方法依賴的package包/類
private Response wrap(SearchResponse response) {
    List<SearchFailure> failures;
    if (response.getShardFailures() == null) {
        failures = emptyList();
    } else {
        failures = new ArrayList<>(response.getShardFailures().length);
        for (ShardSearchFailure failure: response.getShardFailures()) {
            String nodeId = failure.shard() == null ? null : failure.shard().getNodeId();
            failures.add(new SearchFailure(failure.getCause(), failure.index(), failure.shardId(), nodeId));
        }
    }
    List<Hit> hits;
    if (response.getHits().getHits() == null || response.getHits().getHits().length == 0) {
        hits = emptyList();
    } else {
        hits = new ArrayList<>(response.getHits().getHits().length);
        for (SearchHit hit: response.getHits().getHits()) {
            hits.add(new ClientHit(hit));
        }
        hits = unmodifiableList(hits);
    }
    return new Response(response.isTimedOut(), failures, response.getHits().getTotalHits(),
            hits, response.getScrollId());
}
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:25,代碼來源:ClientScrollableHitSource.java

示例3: startScroll

import org.elasticsearch.action.search.SearchResponse; //導入方法依賴的package包/類
/**
 * 開始滾動數據
 *
 * @param queryBuilder 查詢句柄
 * @return 滾動id和當前的一批數據
 */
public Pair<String, List<Webpage>> startScroll(QueryBuilder queryBuilder, int size) {
    SearchRequestBuilder searchRequestBuilder = client.prepareSearch(INDEX_NAME)
            .setTypes(TYPE_NAME)
            .setQuery(queryBuilder)
            .setSize(size)
            .setScroll(TimeValue.timeValueMinutes(SCROLL_TIMEOUT));
    SearchResponse response = searchRequestBuilder.execute().actionGet();
    return new MutablePair<>(response.getScrollId(), warpHits2List(response.getHits()));
}
 
開發者ID:bruceq,項目名稱:Gather-Platform,代碼行數:16,代碼來源:CommonWebpageDAO.java

示例4: exportData

import org.elasticsearch.action.search.SearchResponse; //導入方法依賴的package包/類
/**
 * 導出數據
 * @param builder
 * @param labelsSupplier
 * @param contentSupplier
 * @param out  經過分詞器的輸出流
 */
protected void exportData(QueryBuilder builder, Function<SearchResponse, List<List<String>>> labelsSupplier, 
		Function<SearchResponse, List<String>> contentSupplier, OutputStream out) {
	final int size = 50;
	String scrollId = null;
	int page = 1;
	while(true) {
		LOG.debug("正在輸出第" + page + "頁,query:" + builder);
		SearchResponse response;
		if(StringUtils.isBlank(scrollId)) {
			response = search().setQuery(builder).setSize(size)
					.setScroll(SCROLL_TIMEOUT).get();
			scrollId = response.getScrollId();
		} else {
			response = client.prepareSearchScroll(scrollId)
					.setScroll(SCROLL_TIMEOUT).get();
		}
		final List<List<String>> labels = labelsSupplier.apply(response);
		final List<String> contentList = contentSupplier.apply(response);
		Preconditions.checkNotNull(labels);
		Preconditions.checkNotNull(contentList);
		if(contentList.size()<=0)
			break;
		//開始分詞
		List<String> combine;
		if(labels.size() > 0) {
			combine = labels.stream().map(list -> list.parallelStream().collect(Collectors.joining("/")))
					.collect(Collectors.toList());
			for(int i = 0;i<labels.size();i++) 
				combine.set(i, combine.get(i) + " " + contentList.get(i));
		} else
			combine = contentList;
		page++;
		try {
			IOUtils.write(combine.stream().collect(Collectors.joining("\n")) + "\n", out, "utf-8");
			out.flush();
		} catch(IOException e) {
			LOG.error("文件寫出錯誤, 由於 " + e.getLocalizedMessage());
		}
	}
}
 
開發者ID:TransientBuckwheat,項目名稱:nest-spider,代碼行數:48,代碼來源:ElasticsearchDAO.java

示例5: testCancellationOfScrollSearchesOnFollowupRequests

import org.elasticsearch.action.search.SearchResponse; //導入方法依賴的package包/類
public void testCancellationOfScrollSearchesOnFollowupRequests() throws Exception {

        List<ScriptedBlockPlugin> plugins = initBlockFactory();
        indexTestData();

        // Disable block so the first request would pass
        disableBlocks(plugins);

        logger.info("Executing search");
        TimeValue keepAlive = TimeValue.timeValueSeconds(5);
        SearchResponse searchResponse = client().prepareSearch("test")
            .setScroll(keepAlive)
            .setSize(2)
            .setQuery(
                scriptQuery(new Script(
                    ScriptType.INLINE, "native", NativeTestScriptedBlockFactory.TEST_NATIVE_BLOCK_SCRIPT, Collections.emptyMap())))
            .get();

        assertNotNull(searchResponse.getScrollId());

        // Enable block so the second request would block
        for (ScriptedBlockPlugin plugin : plugins) {
            plugin.scriptedBlockFactory.reset();
            plugin.scriptedBlockFactory.enableBlock();
        }

        String scrollId = searchResponse.getScrollId();
        logger.info("Executing scroll with id {}", scrollId);
        ListenableActionFuture<SearchResponse> scrollResponse = client().prepareSearchScroll(searchResponse.getScrollId())
            .setScroll(keepAlive).execute();

        awaitForBlock(plugins);
        cancelSearch(SearchScrollAction.NAME);
        disableBlocks(plugins);

        SearchResponse response = ensureSearchWasCancelled(scrollResponse);
        if (response != null) {
            // The response didn't fail completely - update scroll id
            scrollId = response.getScrollId();
        }
        logger.info("Cleaning scroll with id {}", scrollId);
        client().prepareClearScroll().addScrollId(scrollId).get();
    }
 
開發者ID:justor,項目名稱:elasticsearch_my,代碼行數:44,代碼來源:SearchCancellationIT.java

示例6: exportData

import org.elasticsearch.action.search.SearchResponse; //導入方法依賴的package包/類
/**
 * 導出數據
 *
 * @param queryBuilder    數據查詢
 * @param labelsSupplier  提取labels,每篇文章返回一個label的List
 * @param contentSupplier 提取正文
 * @return 經過分詞的輸出流
 */
    protected void exportData(QueryBuilder queryBuilder, Function<SearchResponse, List<List<String>>> labelsSupplier, Function<SearchResponse, List<String>> contentSupplier, OutputStream outputStream) {
    final int size = 50;
    String scrollId = null;
    for (int page = 1; ; page++) {
        LOG.debug("正在輸出{}第{}頁", queryBuilder, page);
        SearchResponse response;
        if (StringUtils.isBlank(scrollId)) {
            response = client.prepareSearch(INDEX_NAME)
                    .setTypes(TYPE_NAME)
                    .setQuery(queryBuilder)
                    .setSize(size)
                    .setScroll(TimeValue.timeValueMinutes(SCROLL_TIMEOUT))
                    .execute().actionGet();
            scrollId = response.getScrollId();
        } else {
            response = client.prepareSearchScroll(scrollId)
                    .setScroll(TimeValue.timeValueMinutes(SCROLL_TIMEOUT)).execute().actionGet();
        }
        final List<List<String>> labels = labelsSupplier.apply(response);
        final List<String> contentList = contentSupplier.apply(response);
        Preconditions.checkNotNull(labels);
        Preconditions.checkNotNull(contentList);
        if (contentList.size() <= 0) break;
        List<String> combine;
        if (labels.size() > 0) {
            combine = labels.stream().map(labelList ->
                    labelList.parallelStream().collect(Collectors.joining("/")
                    )).collect(Collectors.toList());
            for (int i = 0; i < labels.size(); i++) {
                String content = contentList.get(i);
                combine.set(i, combine.get(i) + " " + content);
            }
        } else {
            combine = contentList;
        }
        try {
            IOUtils.write(combine.stream().collect(Collectors.joining("\n")) + "\n", outputStream, "utf-8");
            outputStream.flush();
        } catch (IOException e) {
            LOG.error("輸出錯誤,{}", e.getLocalizedMessage());
        }
    }
}
 
開發者ID:bruceq,項目名稱:Gather-Platform,代碼行數:52,代碼來源:IDAO.java

示例7: startScroll

import org.elasticsearch.action.search.SearchResponse; //導入方法依賴的package包/類
public Pair<String, List<Webpage>> startScroll(QueryBuilder builder, int size) {
	SearchResponse response = search().setSize(size).setQuery(builder)
			.setScroll(SCROLL_TIMEOUT).get();
	return new MutablePair<>(response.getScrollId(), hitsToList(response.getHits()));
}
 
開發者ID:TransientBuckwheat,項目名稱:nest-spider,代碼行數:6,代碼來源:WebpageDAO.java


注:本文中的org.elasticsearch.action.search.SearchResponse.getScrollId方法示例由純淨天空整理自Github/MSDocs等開源代碼及文檔管理平台,相關代碼片段篩選自各路編程大神貢獻的開源項目,源碼版權歸原作者所有,傳播和使用請參考對應項目的License;未經允許,請勿轉載。