linwe
2024-09-03 764d883b5ea3bdc06abbec548b6df0511e567978
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
package org.springblade.es.config;
 
import org.springblade.es.service.ElasticsearchIndexInitializer;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.boot.CommandLineRunner;
import org.springframework.stereotype.Component;
// 暂时关闭
//@Component
public class ElasticsearchInitializer implements CommandLineRunner {
 
    private final ElasticsearchIndexInitializer indexInitializer;
 
    @Autowired
    public ElasticsearchInitializer(ElasticsearchIndexInitializer indexInitializer) {
        this.indexInitializer = indexInitializer;
    }
 
    @Override
    public void run(String... args) {
        String indexName = "your_index_name";
        String mappingJson = "{\"properties\":{\"your_field\":{\"type\":\"text\"}}}";
        indexInitializer.initializeIndex(indexName, mappingJson);
    }
}