class DetectorIndexCreatorIfNotPresent implements ApplicationListener<ApplicationReadyEvent> {

    @Override
    public void onApplicationEvent(ApplicationReadyEvent applicationReadyEvent) {
        if (properties.isCreateIndexIfNotFound() && properties.getDetectorIndexName() != null && properties.getDetectorDocType() != null) {
            try {
                boolean isPresent = client.indices().exists(getIndexRequest(), RequestOptions.DEFAULT);
                if (!isPresent) {
                    val response = client.indices().create(createIndexRequest(), RequestOptions.DEFAULT);
                    if (!response.isAcknowledged()) {
                        throw new RuntimeException("Index creation failed");
                    }
                    log.info("Successfully created index: {}", properties.getDetectorIndexName());
                }
            } catch (IOException e) {
                log.error("Index creation failed", e);
                throw new RuntimeException(e);
            }
        }
    }

}