Skip to content

Commit 3fabc15

Browse files
committed
Properly handle underscores in bulk request metadata
Since 6.1.0 all metadata except _index, _type and _id are accepted without the underscore. In 6.5 it produces a deprecation warning and in 7 they are no longer accepted.
1 parent d0433d6 commit 3fabc15

File tree

3 files changed

+18
-3
lines changed

3 files changed

+18
-3
lines changed

CHANGELOG.md

+1
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,7 @@ All notable changes to this project will be documented in this file based on the
77

88
### Bugfixes
99
* Always set the Guzzle `base_uri` to support connecting to multiple ES hosts. [#1618](https://github.com/ruflin/Elastica/pull/1618)
10+
* 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)
1011

1112
### Added
1213

lib/Elastica/Bulk/Action/IndexDocument.php

+15-1
Original file line numberDiff line numberDiff line change
@@ -29,7 +29,9 @@ public function setDocument(Document $document): AbstractDocument
2929
*/
3030
protected function _getMetadata(AbstractUpdateAction $action): array
3131
{
32-
return $action->getOptions([
32+
// see https://github.com/elastic/elasticsearch/issues/26886
33+
// for underscore handling
34+
$options = $action->getOptions([
3335
'index',
3436
'type',
3537
'id',
@@ -39,5 +41,17 @@ protected function _getMetadata(AbstractUpdateAction $action): array
3941
'parent',
4042
'retry_on_conflict',
4143
], true);
44+
45+
$newOptions = \array_intersect_key($options, [
46+
'_index' => 1,
47+
'_type' => 1,
48+
'_id' => 1,
49+
]);
50+
51+
foreach (\array_diff_key($options, $newOptions) as $k => $v) {
52+
$newOptions[\ltrim($k, '_')] = $v;
53+
}
54+
55+
return $newOptions;
4256
}
4357
}

test/Elastica/BulkTest.php

+2-2
Original file line numberDiff line numberDiff line change
@@ -639,7 +639,7 @@ public function testRetry()
639639
$actions = $bulk->getActions();
640640

641641
$metadata = $actions[0]->getMetadata();
642-
$this->assertEquals(5, $metadata['_retry_on_conflict']);
642+
$this->assertEquals(5, $metadata['retry_on_conflict']);
643643

644644
$script = new Script('');
645645
$script->setRetryOnConflict(5);
@@ -650,7 +650,7 @@ public function testRetry()
650650
$actions = $bulk->getActions();
651651

652652
$metadata = $actions[0]->getMetadata();
653-
$this->assertEquals(5, $metadata['_retry_on_conflict']);
653+
$this->assertEquals(5, $metadata['retry_on_conflict']);
654654
}
655655

656656
/**

0 commit comments

Comments
 (0)