diff --git a/src/Elasticsearch/Helper/Iterators/SearchHitIterator.php b/src/Elasticsearch/Helper/Iterators/SearchHitIterator.php index dc7d44877..fbb3892e9 100644 --- a/src/Elasticsearch/Helper/Iterators/SearchHitIterator.php +++ b/src/Elasticsearch/Helper/Iterators/SearchHitIterator.php @@ -77,7 +77,7 @@ public function rewind(): void $this->count = 0; if (isset($current_page['hits']) && isset($current_page['hits']['total'])) { - $this->count = $current_page['hits']['total']; + $this->count = $current_page['hits']['total']['value'] ?? $current_page['hits']['total']; } $this->readPageData(); diff --git a/src/Elasticsearch/Helper/Iterators/SearchResponseIterator.php b/src/Elasticsearch/Helper/Iterators/SearchResponseIterator.php index d8fe694f1..ccb442c26 100644 --- a/src/Elasticsearch/Helper/Iterators/SearchResponseIterator.php +++ b/src/Elasticsearch/Helper/Iterators/SearchResponseIterator.php @@ -100,12 +100,14 @@ private function clearScroll(): void { if (!empty($this->scroll_id)) { $this->client->clearScroll( - array( - 'scroll_id' => $this->scroll_id, - 'client' => array( + [ + 'body' => [ + 'scroll_id' => $this->scroll_id + ], + 'client' => [ 'ignore' => 404 - ) - ) + ] + ] ); $this->scroll_id = null; } @@ -135,8 +137,10 @@ public function next(): void { $this->current_scrolled_response = $this->client->scroll( [ - 'scroll_id' => $this->scroll_id, - 'scroll' => $this->scroll_ttl + 'body' => [ + 'scroll_id' => $this->scroll_id, + 'scroll' => $this->scroll_ttl + ] ] ); $this->scroll_id = $this->current_scrolled_response['_scroll_id']; diff --git a/tests/Elasticsearch/Tests/Helper/Iterators/SearchHitIteratorTest.php b/tests/Elasticsearch/Tests/Helper/Iterators/SearchHitIteratorTest.php index 78980bead..0bff8e156 100644 --- a/tests/Elasticsearch/Tests/Helper/Iterators/SearchHitIteratorTest.php +++ b/tests/Elasticsearch/Tests/Helper/Iterators/SearchHitIteratorTest.php @@ -64,7 +64,10 @@ public function testWithHits() [ 'foo' => 'bar1' ], [ 'foo' => 'bar2' ] ], - 'total' => 3 + 'total' => [ + 'value' => 3, + 'relation' => 'eq' + ] ] ], [ @@ -74,7 +77,10 @@ public function testWithHits() [ 'foo' => 'bar1' ], [ 'foo' => 'bar2' ] ], - 'total' => 3 + 'total' => [ + 'value' => 3, + 'relation' => 'eq' + ] ] ], [ @@ -84,7 +90,10 @@ public function testWithHits() [ 'foo' => 'bar1' ], [ 'foo' => 'bar2' ] ], - 'total' => 3 + 'total' => [ + 'value' => 3, + 'relation' => 'eq' + ] ] ], [ @@ -94,7 +103,10 @@ public function testWithHits() [ 'foo' => 'bar1' ], [ 'foo' => 'bar2' ] ], - 'total' => 3 + 'total' => [ + 'value' => 3, + 'relation' => 'eq' + ] ] ], [ @@ -103,7 +115,10 @@ public function testWithHits() [ 'foo' => 'bar3' ], [ 'foo' => 'bar4' ] ], - 'total' => 2 + 'total' => [ + 'value' => 2, + 'relation' => 'eq' + ] ] ], [ @@ -112,7 +127,10 @@ public function testWithHits() [ 'foo' => 'bar3' ], [ 'foo' => 'bar4' ] ], - 'total' => 2 + 'total' => [ + 'value' => 2, + 'relation' => 'eq' + ] ] ] ); diff --git a/tests/Elasticsearch/Tests/Helper/Iterators/SearchResponseIteratorTest.php b/tests/Elasticsearch/Tests/Helper/Iterators/SearchResponseIteratorTest.php index 07a56f559..1b706dad4 100644 --- a/tests/Elasticsearch/Tests/Helper/Iterators/SearchResponseIteratorTest.php +++ b/tests/Elasticsearch/Tests/Helper/Iterators/SearchResponseIteratorTest.php @@ -100,8 +100,10 @@ public function testWithHits() ->ordered() ->with( [ - 'scroll_id' => 'scroll_id_01', - 'scroll' => '5m' + 'body' => [ + 'scroll_id' => 'scroll_id_01', + 'scroll' => '5m' + ] ] ) ->andReturn( @@ -122,8 +124,10 @@ public function testWithHits() ->ordered() ->with( [ - 'scroll_id' => 'scroll_id_02', - 'scroll' => '5m' + 'body' => [ + 'scroll_id' => 'scroll_id_02', + 'scroll' => '5m' + ] ] ) ->andReturn( @@ -144,8 +148,10 @@ public function testWithHits() ->ordered() ->with( [ - 'scroll_id' => 'scroll_id_03', - 'scroll' => '5m' + 'body' => [ + 'scroll_id' => 'scroll_id_03', + 'scroll' => '5m' + ] ] ) ->andReturn( @@ -161,8 +167,10 @@ public function testWithHits() ->never() ->with( [ - 'scroll_id' => 'scroll_id_04', - 'scroll' => '5m' + 'body' => [ + 'scroll_id' => 'scroll_id_04', + 'scroll' => '5m' + ] ] );