๋กœ์ผ“๐Ÿพ
article thumbnail

 

์ € ๊ฐ™์€ ๊ฒฝ์šฐ Elasitc Search๋ฅผ ์‚ฌ์šฉํ•  ๋•Œ ์ง์ ‘ API ๋ฌธ์„œ ๋ณด๊ณ  ์ž๋ฐ” ์ฝ”๋“œ๋กœ ์ž‘์„ฑํ•ฉ๋‹ˆ๋‹ค.

 

์•„๋ž˜ ๋งํฌ๋Š” Elasitc Search ๊ณต์‹ API Basic Authentication ์ž…๋‹ˆ๋‹ค.

 

Basic authentication | Java REST Client [7.14] | Elastic

Configuring basic authentication can be done by providing an HttpClientConfigCallback while building the RestClient through its builder. The interface has one method that receives an instance of org.apache.http.impl.nio.client.HttpAsyncClientBuilder as an

www.elastic.co

 

์ œ ์„œ๋ฒ„ ํ™˜๊ฒฝ์€ ์•„๋ž˜์™€ ๊ฐ™์Šต๋‹ˆ๋‹ค.

  • CentOS7
  • JDK1.8
  • ElasticSearch 7.13.4

์šฐ์„  ์„ค์น˜๋˜์–ด์žˆ๋Š” ์„œ๋ฒ„๋‚˜ ๋กœ์ปฌ์—์„œ Elastic Search์— ๋ณด์•ˆ์„ค์ •์„ ํ•ด์ฃผ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค.

 

๋ณด์•ˆ์„ค์ •์€ ์•„๋ž˜๋ฅผ ์ฐธ๊ณ ํ•ด์ฃผ์„ธ์š”.

 

[ElasticSearch]Elasticsearch ๋ณด์•ˆ ์ ์šฉ ๋ฐฉ๋ฒ•

ElasticSearch๋Š” url์„ ์ด์šฉํ•ด์„œ ์‰ฝ๊ฒŒ ๋ฐ์ดํ„ฐ ์ „์†ก์ด ๊ฐ€๋Šฅํ•˜๊ธฐ ๋•Œ๋ฌธ์— ElasticSearch๋ฅผ ์ด์šฉํ•˜์—ฌ ์„œ๋น„์Šค๋ฅผ ํ•  ๋•Œ ๋ฐ˜๋“œ์‹œ ๋ณด์•ˆ์„ค์ •์„ ํ•ด์ฃผ์–ด์•ผ ํ•ฉ๋‹ˆ๋‹ค. ๋งŒ์•ฝ ํ•ด์ฃผ์ง€ ์•Š๋Š”๋‹ค๋ฉด ์ž„์˜์˜ ์‚ฌ์šฉ์ž๊ฐ€ ๋งˆ์Œ๋Œ€๋กœ CR

kingofbackend.tistory.com

 

๋ณด์•ˆ์„ค์ •์„ ์™„๋ฃŒํ–ˆ๋‹ค์น˜๊ณ  ์ž๋ฐ”์—์„œ ์ฝ”๋“œ๋กœ ๊ตฌํ˜„ํ•ด๋ณด๊ฒ ์Šต๋‹ˆ๋‹ค.

 

final CredentialsProvider credentialsProvider = new BasicCredentialsProvider();
	credentialsProvider.setCredentials(AuthScope.ANY,
		new UsernamePasswordCredentials(ElasticSearchService.esUserId, ElasticSearchService.esPassword));

RestHighLevelClient client = new RestHighLevelClient(RestClient.builder(
	new HttpHost(serverName, 9200))
	.setHttpClientConfigCallback(new HttpClientConfigCallback() {
    
    @Override
    public HttpAsyncClientBuilder customizeHttpClient(
   	 HttpAsyncClientBuilder httpClientBuilder) {
    	return httpClientBuilder
    		.setDefaultCredentialsProvider(credentialsProvider);
    }
}));

 

๋ฌธ์„œ์— ๋‚˜์™€์žˆ๋Š”๊ฒŒ ๋‹ค ์ž…๋‹ˆ๋‹ค. esUserId, esPassword, serverName๋งŒ ๋ณธ์ธ ํ™˜๊ฒฝ์— ๋งž๊ฒŒ ์„ค์ •ํ•˜๋ฉด ๋ฉ๋‹ˆ๋‹ค. ์œ„ ๊ธ€์—์„œ ์„ค์ •ํ•œ es ๊ณ„์ •์„ ์ž…๋ ฅํ•ด์ฃผ์‹œ๋ฉด ๋ฉ๋‹ˆ๋‹ค.

 

es_user_id=elastic
es_password=1234
serverName=192.168.0.1

 

ํฌ๊ฒŒ ์–ด๋ ค์šด ๋ถ€๋ถ„์€ ์—†๋„ค์š” ใ…Žใ…Ž

 

์ด์ƒ Elasitc Search + Java ์‚ฌ์šฉ์ž ์ธ์ฆ ๊ตฌํ˜„ํ•˜๊ธฐ ์˜€์Šต๋‹ˆ๋‹ค.

profile on loading

Loading...