mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 09:19:04 -04:00
Increase flatten performance of SearchSource (#150658)
This commit is contained in:
parent
807625c108
commit
2406ada16a
1 changed files with 22 additions and 32 deletions
|
@ -59,17 +59,7 @@
|
|||
*/
|
||||
|
||||
import { setWith } from '@kbn/safer-lodash-set';
|
||||
import {
|
||||
difference,
|
||||
isEqual,
|
||||
isFunction,
|
||||
isObject,
|
||||
keyBy,
|
||||
pick,
|
||||
uniqueId,
|
||||
uniqWith,
|
||||
concat,
|
||||
} from 'lodash';
|
||||
import { difference, isEqual, isFunction, isObject, keyBy, pick, uniqueId, concat } from 'lodash';
|
||||
import {
|
||||
catchError,
|
||||
finalize,
|
||||
|
@ -889,28 +879,28 @@ export class SearchSource {
|
|||
// inject the format from the computed fields if one isn't given
|
||||
const docvaluesIndex = keyBy(filteredDocvalueFields, 'field');
|
||||
const bodyFields = this.getFieldsWithoutSourceFilters(index, body.fields);
|
||||
body.fields = uniqWith(
|
||||
bodyFields.concat(filteredDocvalueFields),
|
||||
(fld1: SearchFieldValue, fld2: SearchFieldValue) => {
|
||||
const field1Name = this.getFieldName(fld1);
|
||||
const field2Name = this.getFieldName(fld2);
|
||||
return field1Name === field2Name;
|
||||
|
||||
const uniqueFieldNames = new Set();
|
||||
const uniqueFields = [];
|
||||
for (const field of bodyFields.concat(filteredDocvalueFields)) {
|
||||
const fieldName = this.getFieldName(field);
|
||||
if (metaFields.includes(fieldName) || uniqueFieldNames.has(fieldName)) {
|
||||
continue;
|
||||
}
|
||||
)
|
||||
.filter((fld: SearchFieldValue) => {
|
||||
return !metaFields.includes(this.getFieldName(fld));
|
||||
})
|
||||
.map((fld: SearchFieldValue) => {
|
||||
const fieldName = this.getFieldName(fld);
|
||||
if (Object.keys(docvaluesIndex).includes(fieldName)) {
|
||||
// either provide the field object from computed docvalues,
|
||||
// or merge the user-provided field with the one in docvalues
|
||||
return typeof fld === 'string'
|
||||
? docvaluesIndex[fld]
|
||||
: this.getFieldFromDocValueFieldsOrIndexPattern(docvaluesIndex, fld, index);
|
||||
}
|
||||
return fld;
|
||||
});
|
||||
uniqueFieldNames.add(fieldName);
|
||||
if (Object.keys(docvaluesIndex).includes(fieldName)) {
|
||||
// either provide the field object from computed docvalues,
|
||||
// or merge the user-provided field with the one in docvalues
|
||||
uniqueFields.push(
|
||||
typeof field === 'string'
|
||||
? docvaluesIndex[field]
|
||||
: this.getFieldFromDocValueFieldsOrIndexPattern(docvaluesIndex, field, index)
|
||||
);
|
||||
} else {
|
||||
uniqueFields.push(field);
|
||||
}
|
||||
}
|
||||
body.fields = uniqueFields;
|
||||
}
|
||||
} else {
|
||||
body.fields = filteredDocvalueFields;
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue