[data views] Field retrieval - better handling of closed indices (#177370)

## Summary

The field caps api returns an error if an index pattern matches a closed
index. Now the error is handled and and an empty set is returned.

Closes: https://github.com/elastic/kibana/issues/173954

---------

Co-authored-by: Julia Rechkunova <julia.rechkunova@elastic.co>
This commit is contained in:
Matthew Kime 2024-03-04 08:58:49 -05:00 committed by GitHub
parent 0a2730bd54
commit 9f3bab6d99
No known key found for this signature in database
GPG key ID: B5690EEEBB952194
2 changed files with 19 additions and 0 deletions

View file

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

View file

@ -227,5 +227,20 @@ export default function ({ getService }: FtrProviderContext) {
})
.expect(404);
});
it('returns 200 when index is closed', 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)
.query({ pattern: 'basic_index' })
.expect(200, {
fields: [],
indices: [],
});
});
});
}