Properly filter out system indices in CCS env (#16536)
This commit is contained in:
parent
bf14b4e3e0
commit
75c05459c9
|
@ -93,4 +93,41 @@ describe('getMatchedIndices', () => {
|
|||
]);
|
||||
});
|
||||
});
|
||||
|
||||
describe('systemIndices', () => {
|
||||
it('should return all visible ccs indices', () => {
|
||||
const query = 'cluster_one:*';
|
||||
const indices = [
|
||||
{ name: 'cluster_one:kibana' },
|
||||
{ name: 'cluster_one:es' },
|
||||
{ name: 'cluster_two:kibana' },
|
||||
{ name: 'kibana' },
|
||||
{ name: 'cluster_one:.kibana' },
|
||||
];
|
||||
|
||||
const { visibleIndices } = getMatchedIndices(indices, indices, query, true);
|
||||
expect(visibleIndices).toEqual([
|
||||
{ name: 'cluster_one:kibana' },
|
||||
{ name: 'cluster_one:es' },
|
||||
{ name: 'cluster_one:.kibana' },
|
||||
]);
|
||||
});
|
||||
|
||||
it('should return all visible ccs indices except for system indices', () => {
|
||||
const query = 'cluster_one:*';
|
||||
const indices = [
|
||||
{ name: 'cluster_one:kibana' },
|
||||
{ name: 'cluster_one:es' },
|
||||
{ name: 'cluster_two:kibana' },
|
||||
{ name: 'kibana' },
|
||||
{ name: 'cluster_one:.kibana' },
|
||||
];
|
||||
|
||||
const { visibleIndices } = getMatchedIndices(indices, indices, query, false);
|
||||
expect(visibleIndices).toEqual([
|
||||
{ name: 'cluster_one:kibana' },
|
||||
{ name: 'cluster_one:es' },
|
||||
]);
|
||||
});
|
||||
});
|
||||
});
|
||||
|
|
|
@ -1,6 +1,18 @@
|
|||
import { MAX_NUMBER_OF_MATCHING_INDICES } from '../constants';
|
||||
import { isQueryAMatch } from './is_query_a_match';
|
||||
|
||||
function isSystemIndex(index) {
|
||||
if (index.startsWith('.')) {
|
||||
return true;
|
||||
}
|
||||
|
||||
if (index.includes(':')) {
|
||||
return index.split(':').reduce((isSystem, index) => isSystem || isSystemIndex(index), false);
|
||||
}
|
||||
|
||||
return false;
|
||||
}
|
||||
|
||||
function filterSystemIndices(indices, isIncludingSystemIndices) {
|
||||
if (!indices) {
|
||||
return indices;
|
||||
|
@ -9,7 +21,7 @@ function filterSystemIndices(indices, isIncludingSystemIndices) {
|
|||
const acceptableIndices = isIncludingSystemIndices
|
||||
? indices
|
||||
// All system indices begin with a period.
|
||||
: indices.filter(index => !index.name.startsWith('.'));
|
||||
: indices.filter(index => !isSystemIndex(index.name));
|
||||
|
||||
return acceptableIndices.slice(0, MAX_NUMBER_OF_MATCHING_INDICES);
|
||||
}
|
||||
|
|
Loading…
Reference in a new issue