class MonitoringESDao {

    public void deleteIndices(final int retentionPeriodDays) {
        try {
            final Response response = requestIndices();
            try (BufferedReader reader = new BufferedReader(new InputStreamReader(response.getEntity().getContent()))) {
                final String indicesToDelete = indices(reader)
                        .map(this::withParsedDate)
                        .filter(pair -> pair.right != null && olderThanRetentionPeriod(retentionPeriodDays, pair.right))
                        .map(pair -> pair.left)
                        .collect(Collectors.joining(","));

                lowLevelClient.performRequest(HttpMethod.DELETE.name(), "/" + indicesToDelete);
            }
        } catch (IOException e) {
            throw new PipelineException(e);
        }
    }

    @Autowired public  MonitoringESDao(RestHighLevelClient client, RestClient lowLevelClient);

}