Scroll API for java api 2.3.0

Hi !

I am practicing with the java api for elasticsearch and have a question for scroll api.

According to the online document, SearchType.SCAN should be defined for for setSearchType.

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

SearchResponse scrollResp = client.prepareSearch(test)
.setSearchType(SearchType.SCAN)
.setScroll(new TimeValue(60000))
.setQuery(qb)
.setSize(100).execute().actionGet(); //100 hits per shard will be returned for each scroll

However, according to the search type page, SearchType SCAN is deprecated from v 2.1.0.

https://www.elastic.co/guide/en/elasticsearch/reference/current/search-request-search-type.html

I have checked the code and SCAN is not included in the enum.

So, should I keep using the search type SCAN when I use the scroll api? If not , I appreciate if someone can educate me how to call the SearchResponse object for scroll api in correct way.

I agree that we should have updated the guide within this change: https://github.com/elastic/elasticsearch/issues/12994

You can omit .setSearchType(SearchType.SCAN) but add a sort on _doc. Something similar to:

{
  "sort": [
    "_doc"
  ]
}

Do you want to contribute a documentation change?
If so, you just have to propose changes for this file: https://github.com/elastic/elasticsearch/blob/master/docs/java-api/search.asciidoc

I'll be happy to merge them.

Thanks for reporting!

1 Like

Hello David.

I would be happy to contribute.

I will make changes in the document.

Thanks,
Yu

Would you have the programmatic equivalent of that? Have a very similar use case to port to 5.2.1.