ELK Spring Data 연결
간단히 새로 만들일이 있어서 집에서 심심풀이 삼아 이번엔 highlevel API 또는 이후 버전인 java API 등등 뭐쓸까 고민하다가 highlevel은 사실상 버려졌고 java API로 하자니 하위호환이 쫌 그렇고 해서 스프링 data에 포함된 API를 써서 해봤다.
레퍼넌스 사이트 보고 ( https://docs.spring.io/spring-data/elasticsearch/reference/elasticsearch/template.html )
하는 중인데... 레퍼사이트에 있는 초기화 소스만 하면 에러가 발생 한다.
"Missing [X-Elastic-Product] header. Please check that you are connecting to an Elasticsearch instance, and that any networking filters are preserving that header."
이런 에러 인데 찾아보면 헤더에 X-Elastic-Product 이키를 넣어서 만족시켜라 인데 대강 찾아보면 일반 restclient 관련 내용만 있어서 스프링 데이터에 맞춰서 만들어 보았다. 단순 초기화 용이고 인증은 패스한 버전이니 참고.
Elasticsearch Operations :: Spring Data Elasticsearch
When a document is retrieved with the methods of the DocumentOperations interface, just the found entity will be returned. When searching with the methods of the SearchOperations interface, additional information is available for each entity, for example t
docs.spring.io
@Override
public ClientConfiguration clientConfiguration() {
HttpHeaders httpHeaders = new HttpHeaders();
// httpHeaders.add("X-Elastic-Product", "elasticsearch");
return ClientConfiguration.builder()
.connectedTo("localhost:9200")
.withDefaultHeaders(httpHeaders)
.withClientConfigurer(ElasticsearchClients.ElasticsearchClientConfigurationCallback.from(
httpClientBuilder -> httpClientBuilder
.disableAuthCaching()
.setDefaultHeaders(List.of(new BasicHeader(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_JSON.toString())))
.addInterceptorLast((HttpResponseInterceptor) (response, context) -> response.addHeader("X-Elastic-Product", "Elasticsearch")
)
))
.build();
}
'자바' 카테고리의 다른 글
groovy Json 한글 제어시 UTF8 escape 변환안되게 하기 (1) | 2023.10.24 |
---|---|
Groovy 이미지 변환 코드 (0) | 2023.07.30 |
루씬 숫자형 인덱싱 출력 9.3.0 기준 (0) | 2022.10.07 |
elasticsearch basic auth 인증 코드 (0) | 2022.10.01 |
vscode 이클립스 단축키 똑같이 하기 (0) | 2022.08.07 |