반응형
application.properties 에
elasticsearch.host=192.168.0.50
elasticsearch.cluster_name=master <-- node name
elasticsearch.port=9200 <-- port 기본 9200
elasticsearch.user_name=elastic <-- username
elasticsearch.user_password=설정한 비밀번호
추가 한다.
AbstractElasticsearchConfiguration 확장해서 연결 설정 할 수 있음.
- RestHighLevelClient <-- 사용하는 것을 6.4 이상부터 권장 하고 있음
@Configuration
@EnableElasticsearchRepositories(basePackages = {"com.fourfree.elasticsearch"})
public class ElasticSearchConfig extends AbstractElasticsearchConfiguration {
@Value("${elasticsearch.host}")
private String host;
@Value("${elasticsearch.port}")
private String port;
@Value("${elasticsearch.cluster_name}")
private String clusterName;
@Value("${elasticsearch.user_name}")
private String userName;
@Value("${elasticsearch.user_password}")
private String userPassword;
@Override
@Bean
public RestHighLevelClient elasticsearchClient() {
final ClientConfiguration clientConfiguration = ClientConfiguration.builder()
.connectedTo(host+":" + port)
.withBasicAuth(userName,userPassword)
.build();
return RestClients.create(clientConfiguration).rest();
}
@Bean
public ElasticsearchOperations elasticsearchOperations(){
return new ElasticsearchRestTemplate(elasticsearchClient());
}
}
반응형
'Elasticsearch' 카테고리의 다른 글
@Setting, @Mapping nori 설정 (0) | 2020.11.25 |
---|---|
@Setting, @Mapping nori 설정 (0) | 2020.11.24 |
elasticsearch 버전별 호환체크해두기, pom 버전 확인 (0) | 2020.11.23 |
Elasticsearch 아이디 /비밀번호 설정 (0) | 2020.11.23 |
kibana 설치 (0) | 2020.11.20 |