Skip to content

Latest commit

 

History

History
65 lines (58 loc) · 2.11 KB

README.md

File metadata and controls

65 lines (58 loc) · 2.11 KB

Elastic Client extension for Ktor

Version Java CI with Gradle GitHub License

This module allows to connect to the Elastic Search on application start and use created client instance anywhere inside the Application context.

Quick start

Maven

<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>

Gradle

repositories {
    maven {
        url = uri("https://maven.pkg.github.com/paslavsky/exktor")
    }
}

dependencies {
  implementation "net.paslavsky:ktor-elastic:$exktorVersion"
}

Configure client

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
    }
}

Elastic client

Anywhere inside Application context you could use variable elasticSearchClient (org.elasticsearch.client.RestClient) to access to the Elastic Search cluster.