Untitled
unknown
plain_text
a year ago
1.8 kB
24
Indexable
@Configuration
class ElasticsearchConfig(
@Value("\${spring.elasticsearch.host:}")
private val host: String,
@Value("\${spring.elasticsearch.port:}")
private val port: Int,
@Value("\${spring.elasticsearch.username:}")
private val userName: String,
@Value("\${spring.elasticsearch.password:}")
private val password: String,
@Value("\${spring.profiles.active:local}")
private val profile: String
) : ReactiveElasticsearchConfiguration() {
val log = logger()
override fun clientConfiguration(): ClientConfiguration {
log.info("Trying to connect to $host:$port using client configuration")
return ClientConfiguration.builder()
.connectedTo("$host:$port")
.apply {
if (profile != "local" && profile != "test") {
// Configuration for Opensearch
this.usingSsl()
this.withClientConfigurer(
ElasticsearchClients.ElasticsearchHttpClientConfigurationCallback {
it.addInterceptorFirst(
HttpResponseInterceptor { response, _ ->
response.addHeader("X-Elastic-Product", "Elasticsearch")
}
)
it.addInterceptorLast(
HttpResponseInterceptor { request, _ ->
request.addHeader("Content-Type", MediaType.APPLICATION_JSON_VALUE)
}
)
}
)
}
}
.withBasicAuth(userName, password)
.withSocketTimeout(10000)
.build()
}
}Editor is loading...
Leave a Comment