Skip to content

Conversation

@cbuescher
Copy link
Member

Currently we don't allow retrieving metadata fields through the fields option in search but throw
an error on this case. In #78828 we started to enable this for "_id" if the field is explicitely requested.
This PR adds _ignored and _routing metadata fields which are also internally handled as stored fields to
the list of fields that can be explicitely retrieved.

Relates to #75836

@cbuescher cbuescher added >enhancement :Search/Search Search-related issues that do not fall into other categories v8.0.0 v7.16.0 labels Oct 12, 2021
@cbuescher cbuescher requested a review from romseygeek October 12, 2021 11:28
@elasticmachine elasticmachine added the Team:Search Meta label for search team label Oct 12, 2021
@elasticmachine
Copy link
Collaborator

Pinging @elastic/es-search (Team:Search)

@cbuescher
Copy link
Member Author

fyi I also briefly looked into adding "_source" the same way since it is also kept as a stored field (see
8964620) but reverted it because I realized it is a weird edge case. For example I had a bit of trouble converting the bytes reference that we seem to store the source in back to a usable String for the output in the "fields" section. I don't think this makes much sense. On the other hand we might want to re-think if we want to continue to error if we accidentally request "_source" directly or via an alias. Opinions appreciated.

@cbuescher cbuescher requested a review from jtibshirani October 12, 2021 11:32

- length: { hits.hits.0.fields : 1 }
- match: { hits.hits.0.fields._id.0: "1" }
- length: { hits.hits.1.fields : 1 }
Copy link
Contributor

Choose a reason for hiding this comment

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

This yml test has gotten really large! I find it harder to debug yml tests than unit tests -- would it be possible to add these tests in FieldFetcherTests instead?

Copy link
Member Author

Choose a reason for hiding this comment

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

I can look into that. I already started doing this for "_id" but found it required some amount of mocking etc... because for the metadata fields I think we need to really index documents somewhere, even if it is a mocked out lucene index. But I might be wrong there. I share your opinion that yml tests are harder too debug, thats why I added some basic unit tests to the mapper tests here. I think these additional tests are not that large but I understand the point.

Copy link
Member Author

Choose a reason for hiding this comment

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

One comment though: yml tests are the ones we run against mixed clusters, in upgrade tests etc. so to cover some basic functionality like fetching metadata via "fields" might be good to have anyway, even if I add tests to FieldFetcherTests, wdyt?

Copy link
Contributor

Choose a reason for hiding this comment

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

My perspective is it's great to have high-level coverage in yml tests (for example we already have a test that we can load an example metadata field _id). But for more comprehensive tests (like where we check each field type individually), these make sense as unit tests.

@cbuescher
Copy link
Member Author

@jtibshirani thanks for the first review, I extended the existing FieldFetcherTests for metadata fields and slimmed down the yml test again. I'm not too happy about the amount of mocking/plumbing required that I needed to make the test work. Would appreciate any hint if there are better options, since I think we need an index for these fields to appear.

Copy link
Contributor

@jtibshirani jtibshirani left a comment

Choose a reason for hiding this comment

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

This looks good to me. I don't find the mocking in the test to be excessive, and the test case looks easy to build on.

@cbuescher
Copy link
Member Author

@jtibshirani thanks for the review

@cbuescher cbuescher merged commit 9fa366a into elastic:master Oct 13, 2021
cbuescher pushed a commit to cbuescher/elasticsearch that referenced this pull request Oct 14, 2021
…78981)

Currently we don't allow retrieving metadata fields through the fields option in
search but throw an error on this case. In elastic#78828 we started to enable this for
`_id` if the field is explicitely requested. This PR adds `_ignored` and
`_routing` metadata fields which are also internally handled as stored fields to
the list of fields that can be explicitely retrieved.
cbuescher pushed a commit that referenced this pull request Oct 14, 2021
Currently we exclude metadata fields from being looked up using the fields option in search.
However, as issue like #75836 show, they can still be retrieved e.g. via aliases and then fetching
their values causes errors.
With this change, we enable retrieval of metadata fields (like `_id`, `_ignored` etc.) using the fields
option when the field is explicitely requested. We still continue to exclude any metadata field from
matching wildcard patterns, but they should be retrievable via an exact name or if there is an alias
definition with a path to a metadata field.
This change adds support for the `_id`, `_routing`, `_ignored`, `_index` and `_version` field in particular.

Backport of #78828, #78981 and #79042
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

>enhancement :Search/Search Search-related issues that do not fall into other categories Team:Search Meta label for search team v7.16.0 v8.0.0-beta1

Projects

None yet

Development

Successfully merging this pull request may close these issues.

4 participants