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\Index::forcemerge()` silently dropping the `$args` argument due to a malformed `array_merge()` call. Additional options such as `max_num_segments` and `flush` are now forwarded to Elasticsearch as documented.

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.

This entry describes the forwarding fix, but the PR also changes Index::forcemerge()'s public method signature by adding an array type-hint. If you keep the type change, it should be called out under “Backward Compatibility Breaks” (or the type change should be reverted) so consumers aren’t surprised by a new TypeError.

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


Expand Down
4 changes: 2 additions & 2 deletions src/Index.php
Original file line number Diff line number Diff line change
Expand Up @@ -449,10 +449,10 @@ public function deleteDocuments(array $docs): ResponseSet
* @throws ServerResponseException if the status code of response is 5xx
* @throws ClientException
*/
public function forcemerge($args = []): Response
public function forcemerge(array $args = []): Response
{
Comment on lines +452 to 453

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.

Index::forcemerge() is a public API; narrowing the parameter from untyped to array is a backward-incompatible signature change for any callers currently passing non-arrays (even if those values were previously ignored due to the bug). If BC is a concern for patch/minor releases, consider keeping the parameter untyped and validating/casting internally (or explicitly documenting this as a BC break).

Suggested change
public function forcemerge(array $args = []): Response
{
public function forcemerge($args = []): Response
{
$args = \is_array($args) ? $args : [];

Copilot uses AI. Check for mistakes.
return $this->_client->toElasticaResponse(
$this->_client->indices()->forcemerge(\array_merge(['index' => $this->getName(), $args]))
$this->_client->indices()->forcemerge(\array_merge(['index' => $this->getName()], $args))
);
}

Expand Down
20 changes: 20 additions & 0 deletions tests/IndexTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -794,6 +794,26 @@ public function testForcemerge(): void
$this->assertSame(0, $stats['_all']['primaries']['docs']['deleted']);
}

#[Group('functional')]
public function testForcemergeForwardsArgsToRequest(): void
{
$index = $this->_createIndex();
$index->addDocument(new Document('1', ['foo' => 'bar']));
$index->refresh();

$index->forcemerge(['max_num_segments' => 1, 'flush' => 'true']);

$lastRequest = $index->getClient()->getLastRequest();
$this->assertNotNull($lastRequest);

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

// Without the fix the additional arguments are silently dropped by
// a malformed array_merge() call in Index::forcemerge().
$this->assertSame('1', $query['max_num_segments'] ?? null);
$this->assertSame('true', $query['flush'] ?? null);
}

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