ElasticSearch中Java Scroll API介绍

来源:互联网 发布:sql学生信息管理系统 编辑:程序博客网 时间:2024/05/09 13:47

原文地址:https://www.elastic.co/guide/en/elasticsearch/client/java-api/current/java-search-scrolling.html

Using scrolls in Javaedit

Read the scroll documentation first!

import static org.elasticsearch.index.query.QueryBuilders.*;QueryBuilder qb = termQuery("multi", "test");SearchResponse scrollResp = client.prepareSearch(test)        .addSort(FieldSortBuilder.DOC_FIELD_NAME, SortOrder.ASC)        .setScroll(new TimeValue(60000))        .setQuery(qb)        .setSize(100).get(); //max of 100 hits will be returned for each scroll//Scroll until no hits are returneddo {    for (SearchHit hit : scrollResp.getHits().getHits()) {        //Handle the hit...    }    scrollResp = client.prepareSearchScroll(scrollResp.getScrollId()).setScroll(new TimeValue(60000)).execute().actionGet();} while(scrollResp.getHits().getHits().length != 0); // Zero hits mark the end of the scroll and the while loop.


原创粉丝点击