在yml文件中添加:
es: host: 1111.com port: 9200 index: emp-index type: emp-type
@Autowired
private RestHighLevelClient client;
@Value("${es.index}")
private String indexName;
@Value("${es.type}")
private String typeName;
@Test
void createIndex() throws IOException {
// 1.创建一个请求对象
CreateIndexRequest request = new CreateIndexRequest(indexName);
// 2.sttings -->分片,备份
Settings.Builder builder = Settings.builder();
builder.put("number_of_shards", 3);
builder.put("number_of_replicas", 1);
request.settings(builder);
// 3.mappings -》字段属性,类型
XContentBuilder xContentBuilder = JsonXContent.contentBuilder();
xContentBuilder.
startObject()
.startObject("properties")
.