@VisibleForTesting
    int getNewestIndexNumber() throws NoTargetIndexException {
        final Set<String> indexNames = indices.getIndexNamesAndAliases(getIndexWildcard()).keySet();

        if (indexNames.isEmpty()) {
            throw new NoTargetIndexException("Couldn't find any indices for wildcard " + getIndexWildcard());
        }

        int highestIndexNumber = -1;
        for (String indexName : indexNames) {
            if (!isGraylogDeflectorIndex(indexName)) {
                continue;
            }

            final int currentHighest = highestIndexNumber;
            highestIndexNumber = extractIndexNumber(indexName)
                    .map(indexNumber -> Math.max(indexNumber, currentHighest))
                    .orElse(highestIndexNumber);
        }

        if (highestIndexNumber == -1) {
            throw new NoTargetIndexException("Couldn't get newest index number for indices " + indexNames);
        }

        return highestIndexNumber;
    }
@Test
    public void getNewestTargetNumber() throws NoTargetIndexException {
        final Map<String, Set<String>> indexNameAliases = ImmutableMap.of(
                "graylog_1", Collections.emptySet(),
                "graylog_2", Collections.emptySet(),
                "graylog_3", Collections.singleton("graylog_deflector"),
                "graylog_4_restored_archive", Collections.emptySet());

        when(indices.getIndexNamesAndAliases(anyString())).thenReturn(indexNameAliases);
        final MongoIndexSet mongoIndexSet = createIndexSet(config);

        final int number = mongoIndexSet.getNewestIndexNumber();
        assertEquals(3, number);
    }