Skip to content

Commit cb34f4a

Browse files
committed
Fixes #595
1 parent 2205e99 commit cb34f4a

File tree

2 files changed

+12
-11
lines changed

2 files changed

+12
-11
lines changed

src/Elasticsearch/Helper/Iterators/SearchResponseIterator.php

Lines changed: 5 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -130,15 +130,11 @@ public function rewind()
130130
*/
131131
public function next()
132132
{
133-
if ($this->current_key !== 0) {
134-
$this->current_scrolled_response = $this->client->scroll(
135-
array(
136-
'scroll_id' => $this->scroll_id,
137-
'scroll' => $this->scroll_ttl
138-
)
139-
);
140-
$this->scroll_id = $this->current_scrolled_response['_scroll_id'];
141-
}
133+
$this->current_scrolled_response = $this->client->scroll([
134+
'scroll_id' => $this->scroll_id,
135+
'scroll' => $this->scroll_ttl
136+
]);
137+
$this->scroll_id = $this->current_scrolled_response['_scroll_id'];
142138
$this->current_key++;
143139
}
144140

tests/Elasticsearch/Tests/Helper/Iterators/SearchResponseIteratorTest.php

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -165,7 +165,12 @@ public function testWithHits()
165165
->withAnyArgs();
166166

167167
$responses = new SearchResponseIterator($mock_client, $search_params);
168-
169-
$this->assertCount(4, $responses);
168+
$count = 0;
169+
$i = 0;
170+
foreach ($responses as $response) {
171+
$count += count($response['hits']['hits']);
172+
$this->assertEquals($response['_scroll_id'], sprintf("scroll_id_%02d", ++$i));
173+
}
174+
$this->assertEquals(3, $count);
170175
}
171176
}

0 commit comments

Comments
 (0)