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

SearchSource: fix docvalue_fields and fields intersection logic #46724

Merged
merged 3 commits into from
Oct 4, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
@@ -0,0 +1,25 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

export function filterDocvalueFields(docvalueFields, fields) {
return docvalueFields.filter(docValue => {
const docvalueFieldName = typeof docValue === 'string' ? docValue : docValue.field;
return fields.includes(docvalueFieldName);
});
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,33 @@
/*
* Licensed to Elasticsearch B.V. under one or more contributor
* license agreements. See the NOTICE file distributed with
* this work for additional information regarding copyright
* ownership. Elasticsearch B.V. licenses this file to you under
* the Apache License, Version 2.0 (the "License"); you may
* not use this file except in compliance with the License.
* You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/

import { filterDocvalueFields } from './filter_docvalue_fields';

test('Should exclude docvalue_fields that are not contained in fields', () => {
const docvalueFields = [
'my_ip_field',
{ field: 'my_keyword_field' },
{ field: 'my_date_field', 'format': 'epoch_millis' }
];
const out = filterDocvalueFields(docvalueFields, ['my_ip_field', 'my_keyword_field']);
expect(out).toEqual([
'my_ip_field',
{ field: 'my_keyword_field' },
]);
});
10 changes: 6 additions & 4 deletions src/legacy/ui/public/courier/search_source/search_source.js
Original file line number Diff line number Diff line change
Expand Up @@ -81,6 +81,7 @@ import { searchRequestQueue } from '../search_request_queue';
import { FetchSoonProvider } from '../fetch';
import { FieldWildcardProvider } from '../../field_wildcard';
import { getHighlightRequest } from '../../../../../plugins/data/common/field_formats';
import { filterDocvalueFields } from './filter_docvalue_fields';

const FIELDS = [
'type',
Expand Down Expand Up @@ -551,12 +552,13 @@ export function SearchSourceProvider(Promise, Private, config) {
flatData.body = flatData.body || {};

const computedFields = flatData.index.getComputedFields();

flatData.body.stored_fields = computedFields.storedFields;
flatData.body.script_fields = flatData.body.script_fields || {};
flatData.body.docvalue_fields = flatData.body.docvalue_fields || [];

_.extend(flatData.body.script_fields, computedFields.scriptFields);
flatData.body.docvalue_fields = _.union(flatData.body.docvalue_fields, computedFields.docvalueFields);

const defaultDocValueFields = computedFields.docvalueFields ? computedFields.docvalueFields : [];
flatData.body.docvalue_fields = flatData.body.docvalue_fields || defaultDocValueFields;
nreese marked this conversation as resolved.
Show resolved Hide resolved

if (flatData.body._source) {
// exclude source fields for this index pattern specified by the user
Expand All @@ -570,7 +572,7 @@ export function SearchSourceProvider(Promise, Private, config) {
const fields = flatData.fields;
if (fields) {
// filter out the docvalue_fields, and script_fields to only include those that we are concerned with
flatData.body.docvalue_fields = _.intersection(flatData.body.docvalue_fields, fields);
flatData.body.docvalue_fields = filterDocvalueFields(flatData.body.docvalue_fields, fields);
flatData.body.script_fields = _.pick(flatData.body.script_fields, fields);

// request the remaining fields from both stored_fields and _source
Expand Down