Skip to content

Commit f61c043

Browse files
authored
[Discover][Field caps] Align with the ES responses for closed indices (#199717)
- Closes: #199413 - Related: #199654 - Related ES PR: elastic/elasticsearch#116021 - Related ES PR: elastic/elasticsearch#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
1 parent d78b265 commit f61c043

File tree

2 files changed

+31
-5
lines changed
  • src/plugins/data_views/server/fetcher/lib
  • test/api_integration/apis/data_views/fields_for_wildcard_route

2 files changed

+31
-5
lines changed

src/plugins/data_views/server/fetcher/lib/es_api.ts

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -94,7 +94,10 @@ export async function callFieldCapsApi(params: FieldCapsApiParams) {
9494
);
9595
} catch (error) {
9696
// return an empty set for closed indices
97-
if (error.message.startsWith('cluster_block_exception')) {
97+
if (
98+
error.message.startsWith('index_closed_exception') ||
99+
error.message.startsWith('cluster_block_exception')
100+
) {
98101
return { body: { indices: [], fields: {} } };
99102
}
100103
throw convertEsError(indices, error);

test/api_integration/apis/data_views/fields_for_wildcard_route/response.ts

Lines changed: 27 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -21,6 +21,7 @@ export default function ({ getService }: FtrProviderContext) {
2121
const esArchiver = getService('esArchiver');
2222
const supertest = getService('supertest');
2323
const esClient = getService('es');
24+
const log = getService('log');
2425

2526
const ensureFieldsAreSorted = (resp: { body: { fields: { name: string } } }) => {
2627
expect(resp.body.fields).to.eql(sortBy(resp.body.fields, 'name'));
@@ -80,8 +81,7 @@ export default function ({ getService }: FtrProviderContext) {
8081
},
8182
];
8283

83-
// Failing: See https://github.com/elastic/kibana/issues/199413
84-
describe.skip('fields_for_wildcard_route response', () => {
84+
describe('fields_for_wildcard_route response', () => {
8585
before(() =>
8686
esArchiver.load('test/api_integration/fixtures/es_archiver/index_patterns/basic_index')
8787
);
@@ -240,7 +240,7 @@ export default function ({ getService }: FtrProviderContext) {
240240
.expect(404);
241241
});
242242

243-
it('returns 200 when index is closed', async () => {
243+
it('returns 200 when index is closed and allow_no_index is true', async () => {
244244
const es = getService('es');
245245

246246
await es.indices.close({ index: 'basic_index' });
@@ -249,13 +249,36 @@ export default function ({ getService }: FtrProviderContext) {
249249
.get(FIELDS_FOR_WILDCARD_PATH)
250250
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL)
251251
.set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana')
252-
.query({ pattern: 'basic_index' })
252+
.query({ pattern: 'basic_index', allow_no_index: true })
253+
.expect((response) => {
254+
if (response.statusCode !== 200) {
255+
log.debug(response.body);
256+
}
257+
})
253258
.expect(200, {
254259
fields: [],
255260
indices: [],
256261
});
257262
});
258263

264+
it('returns 404 when index is closed and allow_no_index is false', async () => {
265+
const es = getService('es');
266+
267+
await es.indices.close({ index: 'basic_index' });
268+
269+
await supertest
270+
.get(FIELDS_FOR_WILDCARD_PATH)
271+
.set(ELASTIC_HTTP_VERSION_HEADER, INITIAL_REST_VERSION_INTERNAL)
272+
.set(X_ELASTIC_INTERNAL_ORIGIN_REQUEST, 'kibana')
273+
.query({ pattern: 'basic_index' })
274+
.expect((response) => {
275+
if (response.statusCode !== 404) {
276+
log.debug(response.body);
277+
}
278+
})
279+
.expect(404);
280+
});
281+
259282
it('returns empty set when no fields even if meta fields are supplied', async () => {
260283
await esClient.indices.create({ index: 'fields-for-wildcard-000001' });
261284

0 commit comments

Comments
 (0)