Respect default_field: false when generating index settings (#142277)

This commit is contained in:
Jen Huang 2022-09-30 04:08:51 -07:00 committed by GitHub
parent d92baddf17
commit c43a062ca5
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
3 changed files with 14 additions and 6 deletions

View file

@ -48,6 +48,11 @@ describe('buildDefaultSettings', () => {
name: 'field5Wildcard',
type: 'wildcard',
},
{
name: 'field6NotDefault',
type: 'keyword',
default_field: false,
},
],
});

View file

@ -11,19 +11,20 @@ import type { Field, Fields } from '../../fields/field';
const QUERY_DEFAULT_FIELD_TYPES = ['keyword', 'text', 'match_only_text', 'wildcard'];
const QUERY_DEFAULT_FIELD_LIMIT = 1024;
const flattenFieldsToNameAndType = (
const flattenAndExtractFields = (
fields: Fields,
path: string = ''
): Array<Pick<Field, 'name' | 'type'>> => {
let newFields: Array<Pick<Field, 'name' | 'type'>> = [];
): Array<Pick<Field, 'name' | 'type' | 'default_field'>> => {
let newFields: Array<Pick<Field, 'name' | 'type' | 'default_field'>> = [];
fields.forEach((field) => {
const fieldName = path ? `${path}.${field.name}` : field.name;
newFields.push({
name: fieldName,
type: field.type,
default_field: field.default_field,
});
if (field.fields && field.fields.length) {
newFields = newFields.concat(flattenFieldsToNameAndType(field.fields, fieldName));
newFields = newFields.concat(flattenAndExtractFields(field.fields, fieldName));
}
});
return newFields;
@ -45,8 +46,9 @@ export function buildDefaultSettings({
const logger = appContextService.getLogger();
// Find all field names to set `index.query.default_field` to, which will be
// the first 1024 keyword or text fields
const defaultFields = flattenFieldsToNameAndType(fields).filter(
(field) => field.type && QUERY_DEFAULT_FIELD_TYPES.includes(field.type)
const defaultFields = flattenAndExtractFields(fields).filter(
(field) =>
field.type && QUERY_DEFAULT_FIELD_TYPES.includes(field.type) && field.default_field !== false
);
if (defaultFields.length > QUERY_DEFAULT_FIELD_LIMIT) {
logger.warn(

View file

@ -37,6 +37,7 @@ export interface Field {
include_in_root?: boolean;
null_value?: string;
dimension?: boolean;
default_field?: boolean;
// Meta fields
metric_type?: string;