@Test
public void search() {

  ElasticsearchNodeClient client =
      new ElasticsearchNodeClient(mock(ClusterService.class), nodeClient);
  // Mock first scroll request
  SearchResponse searchResponse = mock(SearchResponse.class);
  when(nodeClient.search(any()).actionGet()).thenReturn(searchResponse);
  when(searchResponse.getScrollId()).thenReturn("scroll123");
  when(searchResponse.getHits())
      .thenReturn(
          new SearchHits(
              new SearchHit[] {searchHit},
              new TotalHits(1L, TotalHits.Relation.EQUAL_TO),
              1.0F));
  when(searchHit.getSourceAsString()).thenReturn("{\"id\", 1}");
  when(factory.construct(any())).thenReturn(exprTupleValue);
  // Mock second scroll request followed
  SearchResponse scrollResponse = mock(SearchResponse.class);
  when(nodeClient.searchScroll(any()).actionGet()).thenReturn(scrollResponse);
  when(scrollResponse.getScrollId()).thenReturn("scroll456");
  when(scrollResponse.getHits()).thenReturn(SearchHits.empty());
  // Verify response for first scroll request
  ElasticsearchScrollRequest request = new ElasticsearchScrollRequest("test", factory);
  ElasticsearchResponse response1 = client.search(request);
  assertFalse(response1.isEmpty());
  Iterator<ExprValue> hits = response1.iterator();
  assertTrue(hits.hasNext());
  assertEquals(exprTupleValue, hits.next());
  assertFalse(hits.hasNext());
  // Verify response for second scroll request
  ElasticsearchResponse response2 = client.search(request);
  assertTrue(response2.isEmpty());
}