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

Change field fetching behavior to automatically add allow_no_index=true when set to ES #151682

Closed
Closed
Show file tree
Hide file tree
Changes from 2 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
4 changes: 2 additions & 2 deletions src/plugins/data_views/common/data_views/data_view.ts
Original file line number Diff line number Diff line change
Expand Up @@ -141,7 +141,7 @@ export class DataView implements DataViewBase {
/**
* Prevents errors when index pattern exists before indices
*/
public readonly allowNoIndex: boolean = false;
public readonly allowNoIndex: boolean = true;
/**
* Name of the data view. Human readable name used to differentiate data view.
*/
Expand Down Expand Up @@ -183,7 +183,7 @@ export class DataView implements DataViewBase {
this.type = spec.type;
this.typeMeta = spec.typeMeta;
this.fieldAttrs = cloneDeep(spec.fieldAttrs) || {};
this.allowNoIndex = spec.allowNoIndex || false;
this.allowNoIndex = spec.allowNoIndex ?? true;
this.runtimeFieldMap = cloneDeep(spec.runtimeFieldMap) || {};
this.namespaces = spec.namespaces || [];
this.name = spec.name || '';
Expand Down
51 changes: 49 additions & 2 deletions src/plugins/data_views/common/data_views/data_views.test.ts
Original file line number Diff line number Diff line change
Expand Up @@ -162,6 +162,41 @@ 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('getFieldsForWildcard called with allowNoIndex set to false if configured', async () => {
const id = '2';
setDocsourcePayload(id, {
id: 'foo',
version: 'foo',
attributes: {
title: 'something',
allowNoIndex: false,
},
});

await indexPatterns.get(id);
expect(apiClient.getFieldsForWildcard).toBeCalledWith({
allowNoIndex: false,
indexFilter: undefined,
metaFields: false,
pattern: 'something',
rollupIndex: undefined,
type: undefined,
});
});

test('does cache ad-hoc data views', async () => {
const id = '1';

Expand Down Expand Up @@ -577,9 +612,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',
};

Expand All @@ -589,5 +623,18 @@ describe('IndexPatterns', () => {
// @ts-expect-error
expect(apiClient.getFieldsForWildcard.mock.calls[0][0].allowNoIndex).toBe(true);
});

test('refreshFields properly includes allowNoIndex=false', async () => {
const indexPatternSpec: DataViewSpec = {
allowNoIndex: false,
title: 'test',
};

const indexPattern = await indexPatterns.create(indexPatternSpec);

indexPatterns.refreshFields(indexPattern);
// @ts-expect-error
expect(apiClient.getFieldsForWildcard.mock.calls[0][0].allowNoIndex).toBe(false);
});
});
});
4 changes: 2 additions & 2 deletions src/plugins/data_views/common/data_views/data_views.ts
Original file line number Diff line number Diff line change
Expand Up @@ -530,7 +530,7 @@ export class DataViewsService {
return this.apiClient.getFieldsForWildcard({
type: dataView.type,
rollupIndex: dataView?.typeMeta?.params?.rollup_index,
allowNoIndex: dataView.allowNoIndex,
allowNoIndex: dataView.allowNoIndex ?? true,
pattern: dataView.getIndexPattern(),
metaFields,
});
Expand All @@ -543,7 +543,7 @@ export class DataViewsService {
metaFields,
type: options.type,
rollupIndex: options.rollupIndex,
allowNoIndex: options.allowNoIndex,
allowNoIndex: options.allowNoIndex ?? true,
Copy link
Member Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@mattkime FYI

Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think since these are private functions we can just permanently set these to true.

indexFilter: options.indexFilter,
});
};
Expand Down