-
Notifications
You must be signed in to change notification settings - Fork 8.3k
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
[Search Source] Fix retrieval of unmapped fields; Add field filters #89837
Conversation
@elasticmachine merge upstream |
⏳ Build in-progress, with failures
Failed CI Steps
History
To update your PR or re-run it, just comment with: |
@@ -539,7 +538,7 @@ export class SearchSource { | |||
if (!body.hasOwnProperty('_source')) { | |||
body._source = sourceFilters; | |||
} | |||
if (body._source.excludes) { | |||
if (body._source && body._source.excludes) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I'm not sure if the check for body._source
is needed? indexPatterns.getSourceFiltering()
will always return something, even if it's just { excludes: [] }
, so if _source
isn't previously set it will already be set in L539.
if (body._source && body._source.excludes) { | ||
// TODO: optimize complexity | ||
remainingFields = remainingFields.filter((remainingField) => { | ||
return !body._source.excludes.includes(remainingField); | ||
}); | ||
} |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
We already have fieldWildcardFilter
above which does this, maybe that can be reused, or this filtering can be done earlier on?
Or actually: It seems like if we know we always want to filter items from excludes
, we should filter body.script_fields
and body.runtime_mappings
as early as possible, so those values are never there to begin with?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, but we'd still need to explicitly exclude fieldsFromSource
, right? So we'd end up with the same result basically?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Agreed, but we'd still need to explicitly exclude fieldsFromSource, right?
Yeah, I guess what I'm getting at is: If remainingFields
is determined by comparing uniqFieldNames
with script_fields and runtime_mappings, and uniqFieldNames
includes fields
and fieldsFromSource
, we could probably do this filtering a bit earlier on in one go by filtering fields
, fieldsFromSource
, script_fields
, and runtime_mappings
. Then you wouldn't have to worry about using any of those items in the rest of the function body because you'd know they are already filtered.
Not a huge concern or anything, just felt like it might make this method (marginally) more readable.
const fieldsToInclude = fields.filter((field) => { | ||
return !sourceFiltersValues.includes(field.name) && !META_FIELDS.includes(field.name); | ||
}); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I may be overlooking something (and things might have changed since I last looked at this stuff), but I'm not sure if this part should be necessary.
The idea with search source is that you provide the index pattern, and this stuff happens internally so you don't need to worry about it. The filtering (and meta fields handling) should already happen inside search source via fieldsWildcardFilter
.
As a consumer of search source, all you should be responsible for is providing a field list, and search source would ideally handle everything else.
But I might be oversimplifying: Is this addressing a case that is not already covered by search source?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
So this particular use case is supposed to take care of field filters
when using the fields API. Unlike _source
, fields API has no notion of excludes
, but rather - includes
. So we'd have to request a list of all fields, except the ones specified by the filters, which is what this code does. The logic doesn't exist (or doesn't work 😅 ) in search_source
yet. TBF, I am not sure where the right place for it is. It felt cleaner to be in Discover, but happy to discuss alternatives.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
fields API has no notion of excludes, but rather - includes. So we'd have to request a list of all fields, except the ones specified by the filters, which is what this code does.
Ah, this is the point I missed. Yeah this does ultimately feel like something search source should handle. I would expect that if you called setField('fields', ['*'])
, then search source would do this internally. But let's see what @ppisljar thinks
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
After some discussions on date_nanos
handling, we have reached the conclusion that Discover would explicitly specify the date format for any date field when requesting fields (#90415 (comment)). I believe this logic belongs to the same place as requesting fields to include, so if we could now decide where that would be, it would be appreciated :)
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Current functionality was that when not setting the fields we would get you all of them. We changed this on the searchSource level, so that we would no longer return unmapped ones when using the fieldsAPI. I think there is place for this logic to live in the searchsource, thus get to the old behaviour. We could also make this optional by exposing `showUnmappedFields' on the searchsource.
it seems from the linked PR that we are handling date_nanos on searchsource level as well, which makes sense imo
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I will change this then so that the logic lives in search source 👍
jenkins test this |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM - This PR does a better job of removing duplicate fields from _source which is great, thanks.
code review, tested in chrome
const request = await searchSource.getSearchRequestBody(); | ||
expect(request.stored_fields).toEqual(['geometry', 'prop1']); | ||
expect(request.docvalue_fields).toEqual(['prop1']); | ||
expect(request._source).toEqual({ |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Thanks for moving this into its own test case.
After inspection, the behavior in master branch, where _source: { includes: ['geometry', 'prop1']}
is not optimal and this PR's behavior is better. It is safe to update the expect statement to _source: { 'geometry'}
. This PR does a better job of removing duplicate fields from _source which is great, thanks.
The existing behavior in master branch results in hits like the below. Notice how prop1's value is returned twice, once in _source and once in fields.
{
"_index": "geo_shapes",
"_id": "4",
"_score": 0,
"_source": {
"prop1": 4,
"geometry": { ...omitted }
},
"fields": {
"prop1": [
4
]
}
}
With this PR in place, the behavior is optimal and prop1's value is only returned a single time.
{
"_index": "geo_shapes",
"_id": "4",
"_score": 0,
"_source": {
"geometry": {...omitted}
},
"fields": {
"prop1": [
4
]
}
}
@elasticmachine merge upstream |
Pinging @elastic/kibana-app (Team:KibanaApp) |
@elasticmachine merge upstream |
@@ -539,7 +595,7 @@ export class SearchSource { | |||
if (!body.hasOwnProperty('_source')) { | |||
body._source = sourceFilters; | |||
} | |||
if (body._source.excludes) { | |||
if (body._source) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
This will always evaluate to true
and can probably be removed. (If body._source
is undefined, we assign it on L596 above, and index.getSourceFiltering()
will always be truthy).
@@ -614,6 +673,7 @@ export class SearchSource { | |||
// if items that are in the docvalueFields are provided, we should | |||
// inject the format from the computed fields if one isn't given | |||
const docvaluesIndex = keyBy(filteredDocvalueFields, 'field'); | |||
body.fields = this.getFieldsWithoutSourceFilters(index, body.fields); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
I haven't run this, but I'm wondering why the logic for getFieldsWithoutSourceFilters
wouldn't be colocated with the other source filtering stuff starting on L599. They are doing very similar things in applying filters to body.fields
, and it seems could be combined (unless there's a reason we need the "unfiltered" values between L599 and here?)
[Edit] Apologies, just realized I'm repeating myself and already mentioned it in the thread above. Been a long week! 😬
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
It's been a long week for all of us, don't worry 😂 Thanks for the comments, will address this soon.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM, thanks for incorporating feedback & braving the murky waters of search source @majagrubic!
@elasticmachine merge upstream |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
LGTM and thanks a lot @majagrubic for making this work!
@elasticmachine merge upstream |
💚 Build SucceededMetrics [docs]Module Count
Async chunks
Page load bundle
History
To update your PR or re-run it, just comment with: |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
…lastic#89837) * [Search Source] Remove includes when retrieving fields from source * Removing unusded imports * Use exclusion filters to retrieve a list of fields * Exclude _source from fields list * Fix small check in getting the field list * Fixing faulty import * Filter logic * Adding a unit test for maps use case * Updating maps unit & functional test * Add unit test * Move logic for requesting a field list inside search_source * Remove unnecessary mock * Code cleanup as per PR comments Co-authored-by: Kibana Machine <[email protected]>
…ndition-for-hiding-recommded-allocation * 'master' of github.com:elastic/kibana: [Discover] Fix toggling multi fields from doc view table (elastic#91121) [ML] Data Frame Analytics: ROC Curve Chart (elastic#89991) skip flaky suite (elastic#86948) skip flaky suite (elastic#91191) Fix date histogram time zone for rollup index (elastic#90632) [Search Source] Fix retrieval of unmapped fields; Add field filters (elastic#89837) [Logs UI] Use useMlHref hook for ML links (elastic#90935) Fix values of `products.min_price` field in Kibana sample ecommerce data set (elastic#90428) [APM] Darker shade for Error group details labels (elastic#91349) [Lens] Adjust new copy for 7.12 (elastic#90413) [ML] Unskip test. Fix modelMemoryLimit value. (elastic#91280) [Lens] Fix empty display name issue in XY chart (elastic#91132) [Lens] Improves error messages when in Dashboard (elastic#90668) [Lens] Keyboard-selected items follow user traversal of drop zones (elastic#90546) [Lens] Improves ranking feature in Top values (elastic#90749) [ILM] Rollover min age tooltip and copy fixes (elastic#91110) # Conflicts: # x-pack/plugins/index_lifecycle_management/__jest__/client_integration/edit_policy/edit_policy.test.ts
…89837) (#91396) * [Search Source] Remove includes when retrieving fields from source * Removing unusded imports * Use exclusion filters to retrieve a list of fields * Exclude _source from fields list * Fix small check in getting the field list * Fixing faulty import * Filter logic * Adding a unit test for maps use case * Updating maps unit & functional test * Add unit test * Move logic for requesting a field list inside search_source * Remove unnecessary mock * Code cleanup as per PR comments Co-authored-by: Kibana Machine <[email protected]> Co-authored-by: Kibana Machine <[email protected]>
Summary
Fixes: #89837
This PR fixes the issue in the current where unmapped fields are not retrieved when retrieving fields from source.
It also adds
source filter
functionality to fields API, by explicitly requesting a list of fields from index pattern that are NOT excluded by the field filters.Checklist
Delete any items that are not applicable to this PR.
For maintainers