Hi, I wrote a program get data use the java scroll API, when set timeout equals 1 second, it seems elasticsearch used about 60 seconds to timeout. I used elasticsearch2.3.1.
here is my code, any suggestion? thanks
@Test
public void testDuelIndexOrder() {
Client client = ElasticClient.getClient();
SearchResponse scroll = client.prepareSearch("ice")
.setSize(1)
.setQuery(QueryBuilders.matchQuery("taskId", "1"))
.addSort(SortBuilders.fieldSort("age"))
.setScroll("1s")
.get();
int scrollDocs = 0;
try {
while (true) {
try {
Thread.sleep(20000);
} catch (InterruptedException e) {
e.printStackTrace();
}
if (scroll.getHits().hits().length == 0) {
break;
}
for (int i = 0; i < scroll.getHits().hits().length; ++i) {
SearchHit scrollHit = scroll.getHits().getAt(i);
}
scrollDocs += scroll.getHits().hits().length;
scroll = client.prepareSearchScroll(scroll.getScrollId()).setScroll("1s").get();
}
} catch (AssertionError e) {
e.printStackTrace();
}finally {
System.out.println(scrollDocs);
client.close();
}
}