class ElasticSearchDataCleaner implements Runnable {

    public BulkByScrollResponse deleteData(ElasticSearchClient elasticSearchClient) {
        log.info("deleting old data");
        BulkByScrollResponse bulkByScrollResponse = null;
        DeleteByQueryRequest deleteByQueryRequest = new DeleteByQueryRequest(INDEX);
        RangeQueryBuilder rangeQueryBuilder = new RangeQueryBuilder(FIELD).lt("now-" + RETENTION_PERIOD_DAYS + "d/d");
        deleteByQueryRequest.setQuery(rangeQueryBuilder);
        try {
            bulkByScrollResponse = elasticSearchClient
                    .deleteByQuery(deleteByQueryRequest, RequestOptions.DEFAULT);
            log.info(bulkByScrollResponse.toString());
        } catch (IOException e) {
            log.error(e.getLocalizedMessage(),e);
        } catch (Exception e) {
            log.error(e.getLocalizedMessage(),e);
        }
        finally {
            elasticSearchClient.close();
        }
        return bulkByScrollResponse;
    }

    public  ElasticSearchDataCleaner();

}