This module allows to connect to the Elastic Search on application start and use created
client instance anywhere inside the Application
context.
<repositories>
<repository>
<id>exktor</id>
<url>https://maven.pkg.github.com/paslavsky/exktor</url>
</repository>
</repositories>
<dependencies>
<dependency>
<groupId>net.paslavsky</groupId>
<artifactId>ktor-elastic</artifactId>
<version>${exktor.version}</version>
</dependency>
</dependencies>
repositories {
maven {
url = uri("https://maven.pkg.github.com/paslavsky/exktor")
}
}
dependencies {
implementation "net.paslavsky:ktor-elastic:$exktorVersion"
}
fun Application.module() {
install(ElasticFeature) {
hosts = arrayOf(HttpHost.create("http://192.168.99.100:9300"))
defaultHeaders = arrayOf(BasicHeader("MyHeader", "MyValue"))
failureListener = {
// Implementation of the RestClient.FailureListener
}
httpClientConfigCallback = {
// Implementation of the RestClientBuilder.HttpClientConfigCallback
}
requestConfigCallback = {
// Implementation of the RestClientBuilder.RequestConfigCallback
}
pathPrefix = "..."
nodeSelector = NodeSelector.ANY
strictDeprecationMode = true
}
}
Anywhere inside Application
context you could use variable elasticSearchClient
(org.elasticsearch.client.RestClient
) to access to the Elastic Search cluster.