有这样一个场景,需要按天提前按天创建好Elasticsearch索引。
下面是一个基本的Spring Boot应用程序,它在应用程序启动时会自动创建一个Elasticsearch索引,并且还会在每天的固定时间自动创建新的索引。此示例中使用的Elasticsearch版本为7.5.1。
import org.elasticsearch.action.admin.indices.create.CreateIndexRequest;
import org.elasticsearch.action.admin.indices.create.CreateIndexResponse;
import org.elasticsearch.client.RequestOptions;
import org.elasticsearch.client.RestHighLevelClient;
import org.elasticsearch.common.xcontent.XContentType;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.scheduling.annotation.EnableScheduling;
import org.springframework.scheduling.annotation.Scheduled;
import java.io.IOException;
import java.text.SimpleDateFormat;
import java.util.Date;
@SpringBootApplication
@Ena