Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Properly handle underscores in update option names #1621

Merged
merged 1 commit into from Mar 29, 2019
Merged
Changes from all commits
Commits
File filter...
Filter file types
Jump to…
Jump to file or symbol
Failed to load files and symbols.

Always

Just for now

@@ -4,9 +4,11 @@ All notable changes to this project will be documented in this file based on the
## [Unreleased](https://github.com/ruflin/Elastica/compare/6.1.1...master)

### Backward Compatibility Breaks
* \Elastica\AbstractUpdateAction::getOptions( $fields ) no longer supports the $underscore parameter, option names must match what elasticsearch expects.

### 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 options and bulk request metadata ([cf upstream](https://github.com/elastic/elasticsearch/issues/26886). [#1621](https://github.com/ruflin/Elastica/pull/1621)

### Added

@@ -17,7 +17,7 @@ All library issues should go to the [issue tracker from github](https://github.c

Compatibility
-------------
This release is compatible with all Elasticsearch 6.x releases. It was tested with version 6.6.1.
This release is compatible with all Elasticsearch 6.1 releases and onwards. It was tested with version 6.6.1.


Contributing
@@ -36,4 +36,4 @@ This project tries to follow Elasticsearch in terms of [End of Life](https://www
| [5.x](https://github.com/ruflin/Elastica/tree/5.x) | 5.x | ^5.0 | \>=5.6 |
| [3.2.3](https://github.com/ruflin/Elastica/tree/3.2.3) (unmaintained) | 2.4.0 | no | \>=5.4 |
| [2.x](https://github.com/ruflin/Elastica/tree/2.x) (unmaintained) | 1.7.2 | no | \>=5.3.3 |
------------
------------
@@ -113,7 +113,7 @@ public function getIndex()
*/
public function setVersion($version)
{
return $this->setParam('_version', (int) $version);
return $this->setParam('version', (int) $version);
}
/**
@@ -123,15 +123,15 @@ public function setVersion($version)
*/
public function getVersion()
{
return $this->getParam('_version');
return $this->getParam('version');
}
/**
* @return bool
*/
public function hasVersion()
{
return $this->hasParam('_version');
return $this->hasParam('version');
}
/**
@@ -144,7 +144,7 @@ public function hasVersion()
*/
public function setVersionType($versionType)
{
return $this->setParam('_version_type', $versionType);
return $this->setParam('version_type', $versionType);
}
/**
@@ -154,15 +154,15 @@ public function setVersionType($versionType)
*/
public function getVersionType()
{
return $this->getParam('_version_type');
return $this->getParam('version_type');
}
/**
* @return bool
*/
public function hasVersionType()
{
return $this->hasParam('_version_type');
return $this->hasParam('version_type');
}
/**
@@ -176,7 +176,7 @@ public function hasVersionType()
*/
public function setParent($parent)
{
return $this->setParam('_parent', $parent);
return $this->setParam('parent', $parent);
}
/**
@@ -186,15 +186,15 @@ public function setParent($parent)
*/
public function getParent()
{
return $this->getParam('_parent');
return $this->getParam('parent');
}
/**
* @return bool
*/
public function hasParent()
{
return $this->hasParam('_parent');
return $this->hasParam('parent');
}
/**
@@ -206,7 +206,7 @@ public function hasParent()
*/
public function setOpType($opType)
{
return $this->setParam('_op_type', $opType);
return $this->setParam('op_type', $opType);
}
/**
@@ -216,15 +216,15 @@ public function setOpType($opType)
*/
public function getOpType()
{
return $this->getParam('_op_type');
return $this->getParam('op_type');
}
/**
* @return bool
*/
public function hasOpType()
{
return $this->hasParam('_op_type');
return $this->hasParam('op_type');
}
/**
@@ -236,7 +236,7 @@ public function hasOpType()
*/
public function setRouting($value)
{
return $this->setParam('_routing', $value);
return $this->setParam('routing', $value);
}
/**
@@ -246,15 +246,15 @@ public function setRouting($value)
*/
public function getRouting()
{
return $this->getParam('_routing');
return $this->getParam('routing');
}
/**
* @return bool
*/
public function hasRouting()
{
return $this->hasParam('_routing');
return $this->hasParam('routing');
}
/**
@@ -268,7 +268,7 @@ public function setFields($fields)
$fields = \implode(',', $fields);
}
return $this->setParam('_fields', (string) $fields);
return $this->setParam('fields', (string) $fields);
}
/**
@@ -284,15 +284,15 @@ public function setFieldsSource()
*/
public function getFields()
{
return $this->getParam('_fields');
return $this->getParam('fields');
}
/**
* @return bool
*/
public function hasFields()
{
return $this->hasParam('_fields');
return $this->hasParam('fields');
}
/**
@@ -302,23 +302,23 @@ public function hasFields()
*/
public function setRetryOnConflict($num)
{
return $this->setParam('_retry_on_conflict', (int) $num);
return $this->setParam('retry_on_conflict', (int) $num);
}
/**
* @return int
*/
public function getRetryOnConflict()
{
return $this->getParam('_retry_on_conflict');
return $this->getParam('retry_on_conflict');
}
/**
* @return bool
*/
public function hasRetryOnConflict()
{
return $this->hasParam('_retry_on_conflict');
return $this->hasParam('retry_on_conflict');
}
/**
@@ -328,23 +328,23 @@ public function hasRetryOnConflict()
*/
public function setRefresh($refresh = true)
{
return $this->setParam('_refresh', (bool) $refresh ? 'true' : 'false');
return $this->setParam('refresh', (bool) $refresh ? 'true' : 'false');
}
/**
* @return bool
*/
public function getRefresh()
{
return 'true' === $this->getParam('_refresh');
return 'true' === $this->getParam('refresh');
}
/**
* @return bool
*/
public function hasRefresh()
{
return $this->hasParam('_refresh');
return $this->hasParam('refresh');
}
/**
@@ -354,23 +354,23 @@ public function hasRefresh()
*/
public function setTimeout($timeout)
{
return $this->setParam('_timeout', $timeout);
return $this->setParam('timeout', $timeout);
}
/**
* @return bool
*/
public function getTimeout()
{
return $this->getParam('_timeout');
return $this->getParam('timeout');
}
/**
* @return bool
*/
public function hasTimeout()
{
return $this->hasParam('_timeout');
return $this->hasParam('timeout');
}
/**
@@ -380,23 +380,23 @@ public function hasTimeout()
*/
public function setConsistency($timeout)
{
return $this->setParam('_consistency', $timeout);
return $this->setParam('consistency', $timeout);
}
/**
* @return string
*/
public function getConsistency()
{
return $this->getParam('_consistency');
return $this->getParam('consistency');
}
/**
* @return bool
*/
public function hasConsistency()
{
return $this->hasParam('_consistency');
return $this->hasParam('consistency');
}
/**
@@ -406,23 +406,23 @@ public function hasConsistency()
*/
public function setReplication($timeout)
{
return $this->setParam('_replication', $timeout);
return $this->setParam('replication', $timeout);
}
/**
* @return string
*/
public function getReplication()
{
return $this->getParam('_replication');
return $this->getParam('replication');
}
/**
* @return bool
*/
public function hasReplication()
{
return $this->hasParam('_replication');
return $this->hasParam('replication');
}
/**
@@ -455,31 +455,16 @@ public function hasUpsert()
}
/**
* @param array $fields if empty array all options will be returned, field names can be either with underscored either without, i.e. _percolate, routing
* @param bool $withUnderscore should option keys contain underscore prefix
* @param array $fields if empty array all options will be returned
*
* @return array
*/
public function getOptions(array $fields = [], $withUnderscore = false)
public function getOptions(array $fields = [])
{
if (!empty($fields)) {
$data = [];
foreach ($fields as $field) {
$key = '_'.\ltrim($field, '_');
if ($this->hasParam($key) && '' !== (string) $this->getParam($key)) {
$data[$key] = $this->getParam($key);
}
}
} else {
$data = $this->getParams();
}
if (!$withUnderscore) {
foreach ($data as $key => $value) {
$data[\ltrim($key, '_')] = $value;
unset($data[$key]);
}
return \array_filter(\array_intersect_key($this->getParams(), \array_flip($fields)));

This comment has been minimized.

Copy link
@ruflin

ruflin Mar 29, 2019

Owner

Nice cleanup.

}
return $data;
return \array_filter($this->getParams());
}
}
@@ -17,13 +17,13 @@ class DeleteDocument extends AbstractDocument
protected function _getMetadata(AbstractUpdateAction $action): array
{
return $action->getOptions([
'index',
'type',
'id',
'_index',
'_type',
'_id',
'version',
'version_type',
'routing',
'parent',
], true);
]);
}
}
@@ -30,14 +30,14 @@ public function setDocument(Document $document): AbstractDocument
protected function _getMetadata(AbstractUpdateAction $action): array
{
return $action->getOptions([
'index',
'type',
'id',
'_index',
'_type',
'_id',
'version',
'version_type',
'routing',
'parent',
'retry_on_conflict',
], true);
]);
}
}
ProTip! Use n and p to navigate between commits in a pull request.
You can’t perform that action at this time.