diff --git a/CHANGELOG.md b/CHANGELOG.md index 530fb40c91..ef33255e91 100755 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file based on the ### Bugfixes * Always set the Guzzle `base_uri` to support connecting to multiple ES hosts. [#1618](https://github.com/ruflin/Elastica/pull/1618) +* Properly handle underscore prefixes in bulk request metadata ([cf upstream](https://github.com/elastic/elasticsearch/issues/26886). [#1621](https://github.com/ruflin/Elastica/pull/1621) ### Added diff --git a/lib/Elastica/Bulk/Action/IndexDocument.php b/lib/Elastica/Bulk/Action/IndexDocument.php index 1003c1bcef..0899ecf4fe 100644 --- a/lib/Elastica/Bulk/Action/IndexDocument.php +++ b/lib/Elastica/Bulk/Action/IndexDocument.php @@ -29,7 +29,9 @@ public function setDocument(Document $document): AbstractDocument */ protected function _getMetadata(AbstractUpdateAction $action): array { - return $action->getOptions([ + // see https://github.com/elastic/elasticsearch/issues/26886 + // for underscore handling + $options = $action->getOptions([ 'index', 'type', 'id', @@ -39,5 +41,17 @@ protected function _getMetadata(AbstractUpdateAction $action): array 'parent', 'retry_on_conflict', ], true); + + $newOptions = \array_intersect_key($options, [ + '_index' => 1, + '_type' => 1, + '_id' => 1, + ]); + + foreach (\array_diff_key($options, $newOptions) as $k => $v) { + $newOptions[\ltrim($k, '_')] = $v; + } + + return $newOptions; } } diff --git a/test/Elastica/BulkTest.php b/test/Elastica/BulkTest.php index 2b24642a31..a47118c92c 100644 --- a/test/Elastica/BulkTest.php +++ b/test/Elastica/BulkTest.php @@ -639,7 +639,7 @@ public function testRetry() $actions = $bulk->getActions(); $metadata = $actions[0]->getMetadata(); - $this->assertEquals(5, $metadata['_retry_on_conflict']); + $this->assertEquals(5, $metadata['retry_on_conflict']); $script = new Script(''); $script->setRetryOnConflict(5); @@ -650,7 +650,7 @@ public function testRetry() $actions = $bulk->getActions(); $metadata = $actions[0]->getMetadata(); - $this->assertEquals(5, $metadata['_retry_on_conflict']); + $this->assertEquals(5, $metadata['retry_on_conflict']); } /**