当前位置: 首页>>代码示例>>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;未经允许,请勿转载。