Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@ and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0
### Deprecated
### Removed
### Fixed
* Fixed `Elastica\Search::count()` silently dropping the `search_type=query_then_fetch` option due to a malformed array literal that wrapped it in a numeric-keyed sub-array.

Copilot AI Apr 30, 2026

Copy link

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

In the Unreleased section, other changelog bullets include a PR/issue reference link; this entry currently has none. Consider appending the PR number link for consistency and easier traceability.

Copilot uses AI. Check for mistakes.
### Security


Expand Down
2 changes: 1 addition & 1 deletion src/Search.php
Original file line number Diff line number Diff line change
Expand Up @@ -329,7 +329,7 @@ public function count($query = '', bool $fullResult = false)

$params = [
'body' => $query->toArray(),
[self::OPTION_SEARCH_TYPE => self::OPTION_SEARCH_TYPE_QUERY_THEN_FETCH],
self::OPTION_SEARCH_TYPE => self::OPTION_SEARCH_TYPE_QUERY_THEN_FETCH,
];

if ($indices = $this->getIndices()) {
Expand Down
26 changes: 26 additions & 0 deletions tests/SearchTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -503,6 +503,32 @@ public function testCountRequest(): void
$this->assertEquals(0, $count);
}

#[Group('functional')]
public function testCountSendsSearchTypeQueryThenFetch(): void
{
$client = $this->_getClient();
$index = $client->getIndex('count_search_type_test');
$index->create([], ['recreate' => true]);
$index->addDocument(new Document('1', ['foo' => 'bar']));
$index->refresh();

$search = new Search($client);
$search->addIndex($index);
$search->count(new MatchAll());

$lastRequest = $client->getLastRequest();
$this->assertNotNull($lastRequest);

\parse_str($lastRequest->getUri()->getQuery(), $query);

// Without the fix, the search_type option was wrapped in a numeric-keyed
// sub-array of $params and silently dropped from the request.
$this->assertSame(
Search::OPTION_SEARCH_TYPE_QUERY_THEN_FETCH,
$query[Search::OPTION_SEARCH_TYPE] ?? null
);
}

#[Group('functional')]
public function testCountRequestGet(): void
{
Expand Down
Loading