-
Notifications
You must be signed in to change notification settings - Fork 25.6k
Closed
Labels
Description
Elasticsearch version (bin/elasticsearch --version): 7.8.0
**HLRC version ** : 6.8.12
Plugins installed: []
JVM version (java -version): "1.8.0_171"
OS version (uname -a if on a Unix-like system): macOs Catalina 10.15.4
Description of the problem including expected versus actual behavior:
The scroll search request has the parameter rest_total_hits_as_int (#46076) but in the next scroll iterations the parameter is missing.
Steps to reproduce:
- Start a 7.8.0 ES cluster
- Using the version 6.8 HLRC in your code
- Write the next test:
import com.google.common.collect.ImmutableMap;
import org.apache.http.HttpHost;
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
import org.elasticsearch.action.admin.indices.refresh.RefreshRequest;
import org.elasticsearch.action.index.IndexRequest;
import org.elasticsearch.action.search.SearchRequest;
import org.elasticsearch.action.search.SearchResponse;
import org.elasticsearch.action.search.SearchScrollRequest;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestClient;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.unit.TimeValue;
import org.elasticsearch.index.query.QueryBuilders;
import org.elasticsearch.search.builder.SearchSourceBuilder;
import org.junit.Test;
@Test
public void testTotalHitsInScrollSearch() throws IOException {
String indexName = "users";
RestHighLevelClient client = new RestHighLevelClient(RestClient.builder(new HttpHost("localhost", 9200, "http")));
client.indices().delete(new DeleteIndexRequest(indexName), RequestOptions.DEFAULT);
for (int i = 0; i < 100; i++) {
Map<String, Object> json = ImmutableMap.of("id", i, "status", "active");
client.index(new IndexRequest(indexName, indexName).source(json), RequestOptions.DEFAULT);
}
client.indices().refresh(new RefreshRequest(indexName), RequestOptions.DEFAULT);
SearchRequest request = new SearchRequest(indexName);
SearchSourceBuilder source = new SearchSourceBuilder();
source.size(5);
source.query(QueryBuilders.termQuery("status", "active"));
request.scroll(TimeValue.timeValueMinutes(1));
request.source(source);
SearchResponse response = client.search(request, RequestOptions.DEFAULT);
assertEquals(5, response.getHits().getHits().length);
assertEquals(100, response.getHits().getTotalHits());
SearchScrollRequest request2 = new SearchScrollRequest(response.getScrollId());
response = client.scroll(request2, RequestOptions.DEFAULT);
assertEquals(5, response.getHits().getHits().length);
assertEquals(100, response.getHits().getTotalHits());
}
Provide logs (if relevant): Test output
java.lang.AssertionError:
Expected :100
Actual :0