mirror of
https://github.com/elastic/kibana.git
synced 2025-04-24 01:38:56 -04:00
[data views] Automatic loading of field lists will no longer error on empty field list (#152059)
## Summary Part of https://github.com/elastic/kibana/issues/151670 and follow up to https://github.com/elastic/kibana/pull/151788 When a data view is loaded, it automatically loads its field list. Previously, it would error if the index pattern failed to match an index. Going forward, this will be treated as a valid empty state - `allowNoIndices` is being passed to the field_caps requests. When `allowNoIndices` is set to true, ES will return a valid empty set rather than a 404 error. ### Checklist - [x] [Unit or functional tests](https://www.elastic.co/guide/en/kibana/master/development-tests.html) were updated or added to match the most common scenarios --------- Co-authored-by: Kibana Machine <42973632+kibanamachine@users.noreply.github.com>
This commit is contained in:
parent
728efb319e
commit
9f8b44df26
4 changed files with 24 additions and 11 deletions
|
@ -164,6 +164,19 @@ describe('IndexPatterns', () => {
|
|||
expect(apiClient.getFieldsForWildcard).toBeCalledTimes(2);
|
||||
});
|
||||
|
||||
test('getFieldsForWildcard called with allowNoIndex set to true as default ', async () => {
|
||||
const id = '1';
|
||||
await indexPatterns.get(id);
|
||||
expect(apiClient.getFieldsForWildcard).toBeCalledWith({
|
||||
allowNoIndex: true,
|
||||
indexFilter: undefined,
|
||||
metaFields: false,
|
||||
pattern: 'something',
|
||||
rollupIndex: undefined,
|
||||
type: undefined,
|
||||
});
|
||||
});
|
||||
|
||||
test('does cache ad-hoc data views', async () => {
|
||||
const id = '1';
|
||||
|
||||
|
@ -608,9 +621,8 @@ describe('IndexPatterns', () => {
|
|||
expect(indexPattern.fields.length).toBe(1);
|
||||
});
|
||||
|
||||
test('refreshFields properly includes allowNoIndex', async () => {
|
||||
test('refreshFields defaults allowNoIndex to true', async () => {
|
||||
const indexPatternSpec: DataViewSpec = {
|
||||
allowNoIndex: true,
|
||||
title: 'test',
|
||||
};
|
||||
|
||||
|
|
|
@ -515,12 +515,12 @@ export class DataViewsService {
|
|||
*/
|
||||
getFieldsForIndexPattern = async (
|
||||
indexPattern: DataView | DataViewSpec,
|
||||
options?: GetFieldsOptions
|
||||
options?: Omit<GetFieldsOptions, 'allowNoIndex'>
|
||||
) =>
|
||||
this.getFieldsForWildcard({
|
||||
type: indexPattern.type,
|
||||
rollupIndex: indexPattern?.typeMeta?.params?.rollup_index,
|
||||
allowNoIndex: indexPattern.allowNoIndex,
|
||||
allowNoIndex: true,
|
||||
...options,
|
||||
pattern: indexPattern.title as string,
|
||||
});
|
||||
|
@ -530,7 +530,7 @@ export class DataViewsService {
|
|||
return this.apiClient.getFieldsForWildcard({
|
||||
type: dataView.type,
|
||||
rollupIndex: dataView?.typeMeta?.params?.rollup_index,
|
||||
allowNoIndex: dataView.allowNoIndex,
|
||||
allowNoIndex: true,
|
||||
pattern: dataView.getIndexPattern(),
|
||||
metaFields,
|
||||
});
|
||||
|
@ -538,12 +538,12 @@ export class DataViewsService {
|
|||
|
||||
private getFieldsAndIndicesForWildcard = async (options: GetFieldsOptions) => {
|
||||
const metaFields = await this.config.get<string[]>(META_FIELDS);
|
||||
return await this.apiClient.getFieldsForWildcard({
|
||||
return this.apiClient.getFieldsForWildcard({
|
||||
pattern: options.pattern,
|
||||
metaFields,
|
||||
type: options.type,
|
||||
rollupIndex: options.rollupIndex,
|
||||
allowNoIndex: options.allowNoIndex,
|
||||
allowNoIndex: true,
|
||||
indexFilter: options.indexFilter,
|
||||
});
|
||||
};
|
||||
|
|
|
@ -50,12 +50,13 @@ export async function getFieldCapabilities(params: FieldCapabilitiesParams) {
|
|||
indexFilter,
|
||||
fields,
|
||||
});
|
||||
const fieldsFromFieldCapsByName = keyBy(readFieldCapsResponse(esFieldCaps.body), 'name');
|
||||
const fieldCapsArr = readFieldCapsResponse(esFieldCaps.body);
|
||||
const fieldsFromFieldCapsByName = keyBy(fieldCapsArr, 'name');
|
||||
|
||||
const allFieldsUnsorted = Object.keys(fieldsFromFieldCapsByName)
|
||||
// not all meta fields are provided, so remove and manually add
|
||||
.filter((name) => !fieldsFromFieldCapsByName[name].metadata_field)
|
||||
.concat(metaFields)
|
||||
.concat(fieldCapsArr.length ? metaFields : [])
|
||||
.reduce<{ names: string[]; map: Map<string, string> }>(
|
||||
(agg, value) => {
|
||||
// This is intentionally using a Map to be highly optimized with very large indexes AND be safe for user provided data
|
||||
|
|
|
@ -426,9 +426,9 @@ export default function ({ getService, getPageObjects }: FtrProviderContext) {
|
|||
await PageObjects.discover.waitUntilSidebarHasLoaded();
|
||||
|
||||
expect(await PageObjects.discover.getSidebarAriaDescription()).to.be(
|
||||
'0 available fields. 0 meta fields.'
|
||||
'0 available fields. 0 empty fields. 0 meta fields.'
|
||||
);
|
||||
await testSubjects.existOrFail(
|
||||
await testSubjects.missingOrFail(
|
||||
`${PageObjects.discover.getSidebarSectionSelector('available')}-fetchWarning`
|
||||
);
|
||||
await testSubjects.existOrFail(
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue