Skip to content

Commit

Permalink
Properly handle underscores in bulk request metadata
Browse files Browse the repository at this point in the history
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.
  • Loading branch information
nomoa committed Mar 27, 2019
1 parent d0433d6 commit 3fabc15
Show file tree
Hide file tree
Showing 3 changed files with 18 additions and 3 deletions.
1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
16 changes: 15 additions & 1 deletion lib/Elastica/Bulk/Action/IndexDocument.php
Original file line number Diff line number Diff line change
Expand Up @@ -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',
Expand All @@ -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;
}
}
4 changes: 2 additions & 2 deletions test/Elastica/BulkTest.php
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand All @@ -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']);
}

/**
Expand Down

0 comments on commit 3fabc15

Please sign in to comment.