i have a treatment in the method run of the CommandLineRunner interface that creates indexes in elasticsearch, the creation of indexes is done after the application is run. in the console of elasticsearch i can see the the creation's trace. for example:
[2018-05-29T14:22:38,579][INFO ][o.e.c.m.MetaDataCreateIndexService] [oYrx3Ep] [country] creating index, cause [api], templates [], shards [5]/[1], mappings []
[2018-05-29T14:23:41,296][INFO ][o.e.c.m.MetaDataCreateIndexService] [oYrx3Ep] [category] creating index, cause [api], templates [], shards [5]/[1], mappings []
...
how can i execute the method when the app is still in the process of being run, i don't want it to be executed after the app is run
@Override
public void run(String... args) throws Exception {
....
try {
Response response = elasticsearchConfiguration.restClient().performRequest("HEAD", "/" + indexName);
Integer statusCode = response.getStatusLine().getStatusCode();
if (statusCode.equals(STATUS_CODE)) {
restHighLevelClient.indices().create(new CreateIndexRequest(indexName));
}
} catch (IOException e) {
logger.error(ERROR + e);
}
....
}