Skip to content

Conversation

ramikg
Copy link
Contributor

@ramikg ramikg commented Nov 4, 2024

Overview

This PR adds the _id field to the object returned by helpers.search.

Motivation

A vast majority of my use cases require knowing the IDs of the documents being fetched, which is why I end up using instead the regular search function instead of the helpers.search handy helper.

Additional considerations

At first I thought about adding an extra parameter to the function (extraOptions?), but after some consideration, I'm not sure that changing the existing behavior would be disruptive.
Still, I don't mind re-implementing this feature in any other manner.

Some notes

  1. _id is an illegal field name, meaning _source will never include it.
  2. Here is the @es_quirk I'm referring to in the comments (exists since version 8.14.0):
    /**
      * @es_quirk '_id' is not available when using 'stored_fields: _none_'
      * on a search request. Otherwise the field is always present on hits.
    */
    
    (In the code I rather not quote it.)

Copy link

cla-checker-service bot commented Nov 4, 2024

💚 CLA has been signed

Copy link
Member

@JoshMock JoshMock left a comment

Choose a reason for hiding this comment

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

This makes complete sense. Thanks for the contribution!

@JoshMock JoshMock merged commit 2455dac into elastic:main Nov 6, 2024
21 checks passed
github-actions bot pushed a commit that referenced this pull request Nov 6, 2024
github-actions bot pushed a commit that referenced this pull request Nov 6, 2024
@ramikg
Copy link
Contributor Author

ramikg commented Nov 6, 2024

Thank you!

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.

2 participants