mirror of
https://github.com/elastic/kibana.git
synced 2025-04-23 17:28:26 -04:00
Index patterns server - throw correct error on field caps 404 (#95879)
* throw correct error on field caps 404 and update tests
This commit is contained in:
parent
d5bb7d6645
commit
d80c257f81
9 changed files with 100 additions and 29 deletions
|
@ -12,6 +12,7 @@ import {
|
|||
IIndexPatternsApiClient,
|
||||
GetFieldsOptionsTimePattern,
|
||||
} from '../../common/index_patterns/types';
|
||||
import { IndexPatternMissingIndices } from '../../common/index_patterns/lib';
|
||||
import { IndexPatternsFetcher } from './fetcher';
|
||||
|
||||
export class IndexPatternsApiServer implements IIndexPatternsApiClient {
|
||||
|
@ -27,12 +28,23 @@ export class IndexPatternsApiServer implements IIndexPatternsApiClient {
|
|||
allowNoIndex,
|
||||
}: GetFieldsOptions) {
|
||||
const indexPatterns = new IndexPatternsFetcher(this.esClient, allowNoIndex);
|
||||
return await indexPatterns.getFieldsForWildcard({
|
||||
pattern,
|
||||
metaFields,
|
||||
type,
|
||||
rollupIndex,
|
||||
});
|
||||
return await indexPatterns
|
||||
.getFieldsForWildcard({
|
||||
pattern,
|
||||
metaFields,
|
||||
type,
|
||||
rollupIndex,
|
||||
})
|
||||
.catch((err) => {
|
||||
if (
|
||||
err.output.payload.statusCode === 404 &&
|
||||
err.output.payload.code === 'no_matching_indices'
|
||||
) {
|
||||
throw new IndexPatternMissingIndices(pattern);
|
||||
} else {
|
||||
throw err;
|
||||
}
|
||||
});
|
||||
}
|
||||
async getFieldsForTimePattern(options: GetFieldsOptionsTimePattern) {
|
||||
const indexPatterns = new IndexPatternsFetcher(this.esClient);
|
||||
|
|
|
@ -71,7 +71,7 @@ export const indexPatternsServiceFactory = ({
|
|||
logger.error(error);
|
||||
},
|
||||
onNotification: ({ title, text }) => {
|
||||
logger.warn(`${title} : ${text}`);
|
||||
logger.warn(`${title}${text ? ` : ${text}` : ''}`);
|
||||
},
|
||||
});
|
||||
};
|
||||
|
|
|
@ -430,7 +430,8 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
});
|
||||
|
||||
it('can set field "format" on an existing field', async () => {
|
||||
const title = `foo-${Date.now()}-${Math.random()}*`;
|
||||
const title = indexPattern.title;
|
||||
await supertest.delete(`/api/index_patterns/index_pattern/${indexPattern.id}`);
|
||||
const response1 = await supertest.post('/api/index_patterns/index_pattern').send({
|
||||
index_pattern: {
|
||||
title,
|
||||
|
|
|
@ -11,8 +11,17 @@ import { FtrProviderContext } from '../../../../ftr_provider_context';
|
|||
|
||||
export default function ({ getService }: FtrProviderContext) {
|
||||
const supertest = getService('supertest');
|
||||
const esArchiver = getService('esArchiver');
|
||||
|
||||
describe('main', () => {
|
||||
before(async () => {
|
||||
await esArchiver.load('index_patterns/basic_index');
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
await esArchiver.unload('index_patterns/basic_index');
|
||||
});
|
||||
|
||||
it('can create a new scripted field', async () => {
|
||||
const title = `foo-${Date.now()}-${Math.random()}*`;
|
||||
const response1 = await supertest.post('/api/index_patterns/index_pattern').send({
|
||||
|
@ -40,7 +49,7 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
});
|
||||
|
||||
it('newly created scripted field is materialized in the index_pattern object', async () => {
|
||||
const title = `foo-${Date.now()}-${Math.random()}*`;
|
||||
const title = `basic_index`;
|
||||
const response1 = await supertest.post('/api/index_patterns/index_pattern').send({
|
||||
index_pattern: {
|
||||
title,
|
||||
|
@ -51,7 +60,7 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
.post(`/api/index_patterns/index_pattern/${response1.body.index_pattern.id}/scripted_field`)
|
||||
.send({
|
||||
field: {
|
||||
name: 'bar',
|
||||
name: 'bar2',
|
||||
type: 'number',
|
||||
scripted: true,
|
||||
script: "doc['field_name'].value",
|
||||
|
@ -64,12 +73,15 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
|
||||
expect(response2.status).to.be(200);
|
||||
|
||||
const field = response2.body.index_pattern.fields.bar;
|
||||
const field = response2.body.index_pattern.fields.bar2;
|
||||
|
||||
expect(field.name).to.be('bar');
|
||||
expect(field.name).to.be('bar2');
|
||||
expect(field.type).to.be('number');
|
||||
expect(field.scripted).to.be(true);
|
||||
expect(field.script).to.be("doc['field_name'].value");
|
||||
await supertest.delete(
|
||||
'/api/index_patterns/index_pattern/' + response1.body.index_pattern.id
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -11,16 +11,25 @@ import { FtrProviderContext } from '../../../../ftr_provider_context';
|
|||
|
||||
export default function ({ getService }: FtrProviderContext) {
|
||||
const supertest = getService('supertest');
|
||||
const esArchiver = getService('esArchiver');
|
||||
|
||||
describe('main', () => {
|
||||
before(async () => {
|
||||
await esArchiver.load('index_patterns/basic_index');
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
await esArchiver.unload('index_patterns/basic_index');
|
||||
});
|
||||
|
||||
it('can remove a scripted field', async () => {
|
||||
const title = `foo-${Date.now()}-${Math.random()}*`;
|
||||
const title = `basic_index`;
|
||||
const response1 = await supertest.post('/api/index_patterns/index_pattern').send({
|
||||
index_pattern: {
|
||||
title,
|
||||
fields: {
|
||||
bar: {
|
||||
name: 'bar',
|
||||
name: 'bar2',
|
||||
type: 'number',
|
||||
scripted: true,
|
||||
script: "doc['field_name'].value",
|
||||
|
@ -33,10 +42,10 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
'/api/index_patterns/index_pattern/' + response1.body.index_pattern.id
|
||||
);
|
||||
|
||||
expect(typeof response2.body.index_pattern.fields.bar).to.be('object');
|
||||
expect(typeof response2.body.index_pattern.fields.bar2).to.be('object');
|
||||
|
||||
const response3 = await supertest.delete(
|
||||
`/api/index_patterns/index_pattern/${response1.body.index_pattern.id}/scripted_field/bar`
|
||||
`/api/index_patterns/index_pattern/${response1.body.index_pattern.id}/scripted_field/bar2`
|
||||
);
|
||||
|
||||
expect(response3.status).to.be(200);
|
||||
|
@ -45,7 +54,10 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
'/api/index_patterns/index_pattern/' + response1.body.index_pattern.id
|
||||
);
|
||||
|
||||
expect(typeof response4.body.index_pattern.fields.bar).to.be('undefined');
|
||||
expect(typeof response4.body.index_pattern.fields.bar2).to.be('undefined');
|
||||
await supertest.delete(
|
||||
'/api/index_patterns/index_pattern/' + response1.body.index_pattern.id
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -11,10 +11,19 @@ import { FtrProviderContext } from '../../../../ftr_provider_context';
|
|||
|
||||
export default function ({ getService }: FtrProviderContext) {
|
||||
const supertest = getService('supertest');
|
||||
const esArchiver = getService('esArchiver');
|
||||
|
||||
describe('main', () => {
|
||||
before(async () => {
|
||||
await esArchiver.load('index_patterns/basic_index');
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
await esArchiver.unload('index_patterns/basic_index');
|
||||
});
|
||||
|
||||
it('can fetch a scripted field', async () => {
|
||||
const title = `foo-${Date.now()}-${Math.random()}*`;
|
||||
const title = `basic_index`;
|
||||
const response1 = await supertest.post('/api/index_patterns/index_pattern').send({
|
||||
index_pattern: {
|
||||
title,
|
||||
|
@ -47,6 +56,9 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
expect(response2.body.field.type).to.be('number');
|
||||
expect(response2.body.field.scripted).to.be(true);
|
||||
expect(response2.body.field.script).to.be("doc['field_name'].value");
|
||||
await supertest.delete(
|
||||
'/api/index_patterns/index_pattern/' + response1.body.index_pattern.id
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -11,10 +11,19 @@ import { FtrProviderContext } from '../../../../ftr_provider_context';
|
|||
|
||||
export default function ({ getService }: FtrProviderContext) {
|
||||
const supertest = getService('supertest');
|
||||
const esArchiver = getService('esArchiver');
|
||||
|
||||
describe('main', () => {
|
||||
before(async () => {
|
||||
await esArchiver.load('index_patterns/basic_index');
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
await esArchiver.unload('index_patterns/basic_index');
|
||||
});
|
||||
|
||||
it('can overwrite an existing field', async () => {
|
||||
const title = `foo-${Date.now()}-${Math.random()}*`;
|
||||
const title = `basic_index`;
|
||||
const response1 = await supertest.post('/api/index_patterns/index_pattern').send({
|
||||
index_pattern: {
|
||||
title,
|
||||
|
@ -63,10 +72,13 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
|
||||
expect(response3.status).to.be(200);
|
||||
expect(response3.body.field.type).to.be('string');
|
||||
await supertest.delete(
|
||||
'/api/index_patterns/index_pattern/' + response1.body.index_pattern.id
|
||||
);
|
||||
});
|
||||
|
||||
it('can add a new scripted field', async () => {
|
||||
const title = `foo-${Date.now()}-${Math.random()}*`;
|
||||
const title = `basic_index`;
|
||||
const response1 = await supertest.post('/api/index_patterns/index_pattern').send({
|
||||
index_pattern: {
|
||||
title,
|
||||
|
@ -100,6 +112,9 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
|
||||
expect(response2.status).to.be(200);
|
||||
expect(response2.body.field.script).to.be("doc['bar'].value");
|
||||
await supertest.delete(
|
||||
'/api/index_patterns/index_pattern/' + response1.body.index_pattern.id
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -11,10 +11,19 @@ import { FtrProviderContext } from '../../../../ftr_provider_context';
|
|||
|
||||
export default function ({ getService }: FtrProviderContext) {
|
||||
const supertest = getService('supertest');
|
||||
const esArchiver = getService('esArchiver');
|
||||
|
||||
describe('main', () => {
|
||||
before(async () => {
|
||||
await esArchiver.load('index_patterns/basic_index');
|
||||
});
|
||||
|
||||
after(async () => {
|
||||
await esArchiver.unload('index_patterns/basic_index');
|
||||
});
|
||||
|
||||
it('can update an existing field', async () => {
|
||||
const title = `foo-${Date.now()}-${Math.random()}*`;
|
||||
const title = `basic_index`;
|
||||
const response1 = await supertest.post('/api/index_patterns/index_pattern').send({
|
||||
index_pattern: {
|
||||
title,
|
||||
|
@ -56,6 +65,9 @@ export default function ({ getService }: FtrProviderContext) {
|
|||
expect(response3.status).to.be(200);
|
||||
expect(response3.body.field.type).to.be('string');
|
||||
expect(response3.body.field.script).to.be("doc['bar'].value");
|
||||
await supertest.delete(
|
||||
'/api/index_patterns/index_pattern/' + response1.body.index_pattern.id
|
||||
);
|
||||
});
|
||||
});
|
||||
}
|
||||
|
|
|
@ -125,8 +125,7 @@ async function isFieldGeoShape(
|
|||
if (!indexPattern) {
|
||||
return false;
|
||||
}
|
||||
const fieldsForIndexPattern = await indexPatternsService.getFieldsForIndexPattern(indexPattern);
|
||||
return fieldsForIndexPattern.some(
|
||||
return indexPattern.fields.some(
|
||||
(fieldDescriptor: IFieldType) => fieldDescriptor.name && fieldDescriptor.name === geoField!
|
||||
);
|
||||
}
|
||||
|
@ -192,13 +191,9 @@ async function filterIndexPatternsByField(fields: string[]) {
|
|||
await Promise.all(
|
||||
indexPatternIds.map(async (indexPatternId: string) => {
|
||||
const indexPattern = await indexPatternsService.get(indexPatternId);
|
||||
const fieldsForIndexPattern = await indexPatternsService.getFieldsForIndexPattern(
|
||||
indexPattern
|
||||
);
|
||||
const containsField = fields.some((field: string) =>
|
||||
fieldsForIndexPattern.some(
|
||||
(fieldDescriptor: IFieldType) =>
|
||||
fieldDescriptor.esTypes && fieldDescriptor.esTypes.includes(field)
|
||||
indexPattern.fields.some(
|
||||
(fieldDescriptor) => fieldDescriptor.esTypes && fieldDescriptor.esTypes.includes(field)
|
||||
)
|
||||
);
|
||||
if (containsField) {
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue