-
Notifications
You must be signed in to change notification settings - Fork 0
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge branch 'main' into refactor/#90
- Loading branch information
Showing
3 changed files
with
38 additions
and
2 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
33 changes: 33 additions & 0 deletions
33
src/main/java/Journey/Together/global/config/ElasticsearchClient.java
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,33 @@ | ||
package Journey.Together.global.config; | ||
|
||
import org.apache.http.client.CredentialsProvider; | ||
import org.elasticsearch.client.RestClient; | ||
import org.elasticsearch.client.RestHighLevelClient; | ||
import org.elasticsearch.client.RestClientBuilder; | ||
import org.apache.http.HttpHost; | ||
import org.apache.http.auth.AuthScope; | ||
import org.apache.http.auth.UsernamePasswordCredentials; | ||
import org.apache.http.impl.client.BasicCredentialsProvider; | ||
import org.apache.http.impl.client.CloseableHttpClient; | ||
import org.apache.http.impl.client.HttpClients; | ||
|
||
public class ElasticsearchClient { | ||
|
||
public static RestHighLevelClient createClient() { | ||
// Elasticsearch 클러스터 호스트와 포트 설정 | ||
HttpHost host = new HttpHost("localhost", 9200, "http"); | ||
|
||
// 인증 정보를 설정 | ||
CredentialsProvider credentialsProvider = new BasicCredentialsProvider(); | ||
credentialsProvider.setCredentials(AuthScope.ANY, new UsernamePasswordCredentials("username", "password")); | ||
|
||
// RestClientBuilder 생성 | ||
RestClientBuilder builder = RestClient.builder(host) | ||
.setHttpClientConfigCallback(httpClientBuilder -> { | ||
return httpClientBuilder.setDefaultCredentialsProvider(credentialsProvider); | ||
}); | ||
|
||
// RestHighLevelClient 생성 | ||
return new RestHighLevelClient(builder); | ||
} | ||
} |