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

Added Elasticsearch::get_documents and Indexable::multi_get #1959

Closed
wants to merge 1 commit into from
Closed

Added Elasticsearch::get_documents and Indexable::multi_get #1959

wants to merge 1 commit into from

Conversation

brandon-m-skinner
Copy link
Contributor

Description of the Change

We needed an easy way to fetch multiple documents per API call, so we added get_documents to the Elasticsearch class and then added multi_get to the Indexable class for ease of use.

Props @nickdaugherty
cc: @rinatkhaziev @pschoffer @netsuso @parkcityj

Alternate Designs

N/A

Benefits

Allows you to get multiple documents per API call.

Possible Drawbacks

N/A

Verification Process

We tested in manually and then started using it in functionality for our search offering which has been running on large sites for months now.

Checklist:

  • I have read the CONTRIBUTING document.
  • My code follows the code style of this project.
  • My change requires a change to the documentation.
  • I have updated the documentation accordingly.
  • I have added tests to cover my change.
  • All new and existing tests passed.

Applicable Issues

Changelog Entry

Added Elasticsearch::get_documents and Indexable::multi_get. Props @nickdaugherty

@tlovett1
Copy link
Member

@brandon-m-skinner will this only work with ES 7.0+?

@brandon-m-skinner
Copy link
Contributor Author

5.0 and higher

* @return boolean|array
*/
public function get_documents( $index, $document_ids ) {
$path = $index . '/_doc/_mget';
Copy link
Member

@felipeelia felipeelia Mar 5, 2021

Choose a reason for hiding this comment

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

Unfortunately, this doesn't work with Elasticsearch 5. To have it working on versions older than 7, we'll have to replicate the code we have here and in some other parts of this same class. Something like this:

if ( version_compare( $this->get_elasticsearch_version(), '7.0', '<' ) ) {
	$path = apply_filters( 'ep_index_' . $type . '_request_path', $index . '/' . $type . '/_mget', $document_ids, $type );
} else {
	$path = apply_filters( 'ep_index_' . $type . '_request_path', $index . '/_doc/_mget', $document_ids, $type );
}

It'll also be needed to pass the $type as a parameter to the get_documents method. Something like:

return Elasticsearch::factory()->get_documents( $this->get_index_name(), $this->slug, $object_ids );

Would it be possible to have these changes applied to this PR, @brandon-m-skinner? Thanks!

@felipeelia
Copy link
Member

Closing it in favor or #2210. Thanks!

@felipeelia felipeelia closed this May 21, 2021
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
Development

Successfully merging this pull request may close these issues.

6 participants