[Discover][Field caps] Align with the ES responses for closed indices (#199717)

- Closes: https://github.com/elastic/kibana/issues/199413
- Related: https://github.com/elastic/kibana/pull/199654
- Related ES PR: https://github.com/elastic/elasticsearch/pull/116021
- Related ES PR: https://github.com/elastic/elasticsearch/pull/116656

## Summary

This PR unskips tests and updates the Kibana API to the updated ES
responses.


### 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
This commit is contained in:
Julia Rechkunova 2024-11-19 11:42:28 +01:00 committed by GitHub
parent d78b265423
commit f61c043bf6
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 34 additions and 8 deletions

View file

@ -94,7 +94,10 @@ export async function callFieldCapsApi(params: FieldCapsApiParams) {
);
} catch (error) {
// return an empty set for closed indices
if (error.message.startsWith('cluster_block_exception')) {
if (
error.message.startsWith('index_closed_exception') ||
error.message.startsWith('cluster_block_exception')
) {
return { body: { indices: [], fields: {} } };
}
throw convertEsError(indices, error);

View file

@ -21,6 +21,7 @@ export default function ({ getService }: FtrProviderContext) {
const esArchiver = getService('esArchiver');
const supertest = getService('supertest');
const esClient = getService('es');
const log = getService('log');
const ensureFieldsAreSorted = (resp: { body: { fields: { name: string } } }) => {
expect(resp.body.fields).to.eql(sortBy(resp.body.fields, 'name'));
@ -80,8 +81,7 @@ export default function ({ getService }: FtrProviderContext) {
},
];
// Failing: See https://github.com/elastic/kibana/issues/199413
describe.skip('fields_for_wildcard_route response', () => {
describe('fields_for_wildcard_route response', () => {
before(() =>
esArchiver.load('test/api_integration/fixtures/es_archiver/index_patterns/basic_index')
);
@ -240,7 +240,28 @@ export default function ({ getService }: FtrProviderContext) {
.expect(404);
});
it('returns 200 when index is closed', async () => {
it('returns 200 when index is closed and allow_no_index is true', async () => {
const es = getService('es');
await es.indices.close({ index: 'basic_index' });
await supertest
.get(FIELDS_FOR_WILDCARD_PATH)
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL)
.set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana')
.query({ pattern: 'basic_index', allow_no_index: true })
.expect((response) => {
if (response.statusCode !== 200) {
log.debug(response.body);
}
})
.expect(200, {
fields: [],
indices: [],
});
});
it('returns 404 when index is closed and allow_no_index is false', async () => {
const es = getService('es');
await es.indices.close({ index: 'basic_index' });
@ -250,10 +271,12 @@ export default function ({ getService }: FtrProviderContext) {
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL)
.set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana')
.query({ pattern: 'basic_index' })
.expect(200, {
fields: [],
indices: [],
});
.expect((response) => {
if (response.statusCode !== 404) {
log.debug(response.body);
}
})
.expect(404);
});
it('returns empty set when no fields even if meta fields are supplied', async () => {