```
/**
*Description TODO
*@Author liufei
*@DATE 2019/11/4 15:50
**/
//@Configuration
public class RestClientConfig extends AbstractElasticsearchConfiguration {
/**
* Setting up the High Level REST Client.
* @return
*/
@Override
public RestHighLevelClient elasticsearchClient() {
return RestClients.create(ClientConfiguration.localhost()).rest();
}
// no special bean creation needed
// 基类AbstractElasticsearchConfiguration已经提供了elasticsearchTemplate bean
// use the ElasticsearchEntityMapper 使用元模型对象映射 ElasticsearchMappe
@Bean
@Override
public EntityMapper entityMapper() {
ElasticsearchEntityMapper entityMapper = new ElasticsearchEntityMapper(elasticsearchMappingContext(),
new DefaultConversionService());
entityMapper.setConversions(elasticsearchCustomConversions());
return entityMapper;
}
}
```
```
/**
* 高级rest客户端索引创建
* @return
*/
@PostMapping("/person/high")
public String highSave(@RequestBody Person person){
IndexRequest request = new IndexRequest("demo-person", "_doc", person.getId().toString())
.source(person, XContentType.JSON)
.setRefreshPolicy(IMMEDIATE);
IndexResponse response;
try {
response = highLevelClient.index(request);
} catch (IOException e) {
e.printStackTrace();
}
return "success";
}
```