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

Allow to pass native endpoint options to index creation #1859

Merged
merged 3 commits into from
Nov 16, 2020

Conversation

deguif
Copy link
Collaborator

@deguif deguif commented Oct 30, 2020

This PR will allow to pass endpoint query parameters to index creation: https://www.elastic.co/guide/en/elasticsearch/reference/current/indices-create-index.html#indices-create-api-query-params

The list of available options is retrieved from the corresponding elasticsearch endpoint class to avoid maintaining it here.

@deguif deguif force-pushed the create-index-options branch 2 times, most recently from ed93a8d to 2df1cd5 Compare October 30, 2020 16:11
@@ -422,7 +423,9 @@ public function create(array $args = [], $options = null): Response
}
}

$endpoint = new Create();
unset($options['recreate']);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Can you share why this is needed now?

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Yes, I had in mind to use option wait_for_active_shards when creating indexes on ES.
This would remove the need to have the function Elastica\Test\Base::_waitForAllocation() for example by simply passing this option when creating the index.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I need to read up on my end what this flag does or doesn't.

Is it now with the new code that recreate or was this always the case and now we remove it but didn't before? Trying to understand which part is related to the change of getting the options and what is further improvements.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

The unset is here only to remove invalid endpoint options so that these options can be passed to the endpoint via setParams().

@@ -402,9 +402,10 @@ public function create(array $args = [], $options = null): Response
throw new \TypeError(\sprintf('Argument 2 passed to "%s()" must be of type array|bool|null, %s given.', __METHOD__, \is_object($options) ? \get_class($options) : \gettype($options)));
}

$invalidOptions = \array_diff(\array_keys($options), $allowedOptions = [
$endpoint = new Create();
$invalidOptions = \array_diff(\array_keys($options), $allowedOptions = \array_merge($endpoint->getParamWhitelist(), [
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

If I understand this correctly, it adds an additional call to Elasticsearch each time before an index is created? Assuming index creation is not happening too often, this is probably not a problem but worth mentioning.

Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

No extra call to Elasticsearch, just the valid options are retrieved from the underlying endpoint class.

Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, good to know. I somehow assumed it gets it from ES each time.

@@ -422,7 +423,9 @@ public function create(array $args = [], $options = null): Response
}
}

$endpoint = new Create();
unset($options['recreate']);
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think I need to read up on my end what this flag does or doesn't.

Is it now with the new code that recreate or was this always the case and now we remove it but didn't before? Trying to understand which part is related to the change of getting the options and what is further improvements.

@@ -402,9 +402,10 @@ public function create(array $args = [], $options = null): Response
throw new \TypeError(\sprintf('Argument 2 passed to "%s()" must be of type array|bool|null, %s given.', __METHOD__, \is_object($options) ? \get_class($options) : \gettype($options)));
}

$invalidOptions = \array_diff(\array_keys($options), $allowedOptions = [
$endpoint = new Create();
$invalidOptions = \array_diff(\array_keys($options), $allowedOptions = \array_merge($endpoint->getParamWhitelist(), [
Copy link
Owner

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Ah, good to know. I somehow assumed it gets it from ES each time.

@deguif
Copy link
Collaborator Author

deguif commented Nov 16, 2020

Waiting for #1867 to be merged before merging this one as I will have to update the tests.

@deguif deguif force-pushed the create-index-options branch from fc8cda4 to 0c398af Compare November 16, 2020 13:49
$index->create([]);
$this->_waitForAllocation($index);
$index->create([], [
'wait_for_active_shards' => 'all',
Copy link
Collaborator Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Here's a concrete example of the use of native options when creating an index.
This allows to replace the use of $this->_waitForAllocation() by a native option.

@deguif deguif merged commit 4d974b4 into ruflin:master Nov 16, 2020
@deguif deguif deleted the create-index-options branch March 19, 2021 15:55
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

2 participants