# Limited scroll search from java

**URL:** <https://discuss.elastic.co/t/limited-scroll-search-from-java/23130>\
**Category:** Elasticsearch\
**Created:** [April 7, 2015, 1:54pm UTC](https://discuss.elastic.co/t/limited-scroll-search-from-java/23130 "2015-04-07T13:54:42Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Robert\_Fiser](https://avatars.discourse-cdn.com/v4/letter/r/e9c0ed/32.png) [@Robert\_Fiser](https://discuss.elastic.co/u/Robert_Fiser)\
**Post date:** [April 7, 2015, 1:54pm UTC](https://discuss.elastic.co/t/limited-scroll-search-from-java/23130/1 "2015-04-07T13:54:42Z")

</div>

Hi,  
we have many indexes each with one or more aliases each with one shard and  
each created from same template.  
I want to fire scroll search with limit to one or more indexes by one or  
more aliases. If I set a size parameter its applied to result from a shard  
not to whole result which i've expected. If i set a post limit filter then  
no data are returned.  
I want to set size to ONE and get ONE result even if i hit a 15 shards. Now  
i gets 15 results or nothing.  
What's wrong?

String[] aliases = getAliases(input);  
SearchRequestBuilder requestBuilder = esConnection.prepareSearch(aliases);

BoolQueryBuilder boolQuery = boolQuery();  
boolQuery =  
boolQuery.must(rangeQuery("created\_time").from(input.getTimeFrom()).to(input.getTimeTo()));  
...  
requestBuilder.setQuery(boolQuery);

requestBuilder.setSearchType(SearchType.SCAN);  
requestBuilder.setTypes("type");  
requestBuilder.addSort("created\_time", SortOrder.DESC);  
requestBuilder.setExplain(false);  
requestBuilder.setFetchSource(false);  
requestBuilder.setNoFields();  
requestBuilder.setSize(input.getLimit());  
//  
requestBuilder.setPostFilter(FilterBuilders.limitFilter(input.getLimit()));  
requestBuilder.setScroll(new TimeValue(1, TimeUnit.MINUTES));

ListenableActionFuture execute = requestBuilder.execute();  
SearchResponse searchResponse = execute.actionGet();

searchResponse =  
esConnection.prepareSearchScroll(searchResponse.getScrollId())  
.execute().actionGet();

SearchHits hits = searchResponse.getHits();  
List result = new ArrayList\<\>();  
for (SearchHit searchHit : hits.getHits()) {  
result.add(searchHit.getId());  
}

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/fa959fb9-731a-43a4-b89f-939bd245fa9d%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/fa959fb9-731a-43a4-b89f-939bd245fa9d%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 6, 2017, 12:21am UTC](https://discuss.elastic.co/t/limited-scroll-search-from-java/23130/2 "2017-07-06T00:21:09Z")

</div>


