Skip to content

The parameter rest_total_hits_as_int in HLRC in the next scroll request iteration is missing #61677

@silvinalucero

Description

@silvinalucero

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:

  1. Start a 7.8.0 ES cluster
  2. Using the version 6.8 HLRC in your code
org.elasticsearch elasticsearch 6.8.4
  1. 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

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions