我在CommandLineRunner接口的方法运行中有一个处理方法,它在elasticsearch中创建索引,索引的创建在应用程序运行后完成。在elasticsearch的控制台中,我可以看到创作的痕迹。例如:
[2018-05-29T14:22:38,579] [INFO] [o.e.c.m.MetaDataCreateIndexService] [oYrx3Ep] [country]创建索引,导致[api],templates [],分片 [5] / [1],映射[]
[2018-05-29T14:23:41,296] [INFO] [o.e.c.m.MetaDataCreateIndexService] [oYrx3Ep] [category]创建索引,导致[api],templates [],分片 [5] / [1],映射[]
...
如何在应用程序仍在运行的过程中执行该方法,我不希望它在应用程序运行后执行
@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);
}
....
}