Elasticsearch scroll api search "from"
In Java, it can be done as follows
QueryBuilder query = QueryBuilders.matchAllQuery();SearchResponse scrollResp = Constants.client.prepareSearch(index) .setTypes(type).setSearchType(SearchType.SCAN) .setScroll(new TimeValue(600000)).setQuery(query) .setSize(500).execute().actionGet();while (true) { scrollResp = Constants.client .prepareSearchScroll(scrollResp.getScrollId()) .setScroll(new TimeValue(600000)).execute().actionGet(); System.out.println("Record count :" + scrollResp.getHits().getHits().length); total = total + scrollResp.getHits().getHits().length; System.out.println("Total record count: " + total); for (SearchHit hit : scrollResp.getHits()) { //handle the hit } // Break condition: No hits are returned if (scrollResp.getHits().getHits().length == 0) { System.out.println("All records are fetched"); break; }}
Hope it helps.