From 7412eb3387560eaa845a1abee0cf079f2c61c6d1 Mon Sep 17 00:00:00 2001 From: Marius Barbulescu Date: Sat, 6 Jan 2024 19:25:29 +0100 Subject: [PATCH] change refreshInterval to Duration --- README.md | 2 +- .../manual/bulk/indexmanagement/index-management.kt | 3 ++- docs/src/test/kotlin/documentation/projectreadme/readme.kt | 5 ++--- .../kotlin/com/jillesvangurp/ktsearch/reindex-api.kt | 4 ++-- .../kotlin/com/jillesvangurp/ktsearch/request-dsl.kt | 4 ++-- .../kotlin/com/jillesvangurp/ktsearch/IndexCreateTest.kt | 3 ++- .../com/jillesvangurp/searchdsls/mappingdsl/IndexSettings.kt | 3 ++- 7 files changed, 13 insertions(+), 11 deletions(-) diff --git a/README.md b/README.md index 0e3ac1a9..7b43f47a 100644 --- a/README.md +++ b/README.md @@ -124,7 +124,7 @@ client.createIndex(indexName) { settings { replicas = 0 shards = 3 - refreshInterval = "10s" + refreshInterval = 10.seconds } mappings(dynamicEnabled = false) { text(TestDocument::name) diff --git a/docs/src/test/kotlin/documentation/manual/bulk/indexmanagement/index-management.kt b/docs/src/test/kotlin/documentation/manual/bulk/indexmanagement/index-management.kt index 7ff84e62..5c2aef4d 100644 --- a/docs/src/test/kotlin/documentation/manual/bulk/indexmanagement/index-management.kt +++ b/docs/src/test/kotlin/documentation/manual/bulk/indexmanagement/index-management.kt @@ -5,6 +5,7 @@ import documentation.manual.ManualPages import documentation.mdLink import documentation.sourceGitRepository import kotlinx.coroutines.runBlocking +import kotlin.time.Duration.Companion.seconds val indexManagementMd = sourceGitRepository.md { val client = SearchClient(KtorRestClient(Node("localhost", 9999))) @@ -54,7 +55,7 @@ val indexManagementMd = sourceGitRepository.md { settings { replicas = 1 shards = 3 - refreshInterval = "10s" + refreshInterval = 10.seconds analysis { filter("2_5_edgengrams") { diff --git a/docs/src/test/kotlin/documentation/projectreadme/readme.kt b/docs/src/test/kotlin/documentation/projectreadme/readme.kt index bdd023a8..233597c7 100644 --- a/docs/src/test/kotlin/documentation/projectreadme/readme.kt +++ b/docs/src/test/kotlin/documentation/projectreadme/readme.kt @@ -2,8 +2,6 @@ package documentation.projectreadme -import com.jillesvangurp.kotlin4example.ExampleOutput -import com.jillesvangurp.kotlin4example.Kotlin4Example import com.jillesvangurp.ktsearch.* import com.jillesvangurp.searchdsls.querydsl.* import documentation.githubLink @@ -13,6 +11,7 @@ import documentation.printStdOut import documentation.sourceGitRepository import kotlinx.coroutines.runBlocking import kotlinx.serialization.Serializable +import kotlin.time.Duration.Companion.seconds val projectReadme = sourceGitRepository.md { +""" @@ -103,7 +102,7 @@ val projectReadme = sourceGitRepository.md { settings { replicas = 0 shards = 3 - refreshInterval = "10s" + refreshInterval = 10.seconds } mappings(dynamicEnabled = false) { text(TestDocument::name) diff --git a/search-client/src/commonMain/kotlin/com/jillesvangurp/ktsearch/reindex-api.kt b/search-client/src/commonMain/kotlin/com/jillesvangurp/ktsearch/reindex-api.kt index 530be7fc..ee30b6e4 100644 --- a/search-client/src/commonMain/kotlin/com/jillesvangurp/ktsearch/reindex-api.kt +++ b/search-client/src/commonMain/kotlin/com/jillesvangurp/ktsearch/reindex-api.kt @@ -56,12 +56,12 @@ suspend fun SearchClient.reindex( return restClient.post { path("_reindex") parameter("refresh", refresh) - parameter("timeout", timeout.toElasticsearchTimeUnit()) + parameter("timeout", timeout) parameter("wait_for_active_shards", waitForActiveShards) parameter("wait_for_completion", waitForCompletion) parameter("requests_per_second", requestsPerSecond) parameter("require_alias", requireAlias) - parameter("scroll", scroll.toElasticsearchTimeUnit()) + parameter("scroll", scroll) parameter("slices", slices) parameter("max_docs", maxDocs) body = reindexDSL.toString() diff --git a/search-client/src/commonMain/kotlin/com/jillesvangurp/ktsearch/request-dsl.kt b/search-client/src/commonMain/kotlin/com/jillesvangurp/ktsearch/request-dsl.kt index 0b94cd71..d7ffeef2 100644 --- a/search-client/src/commonMain/kotlin/com/jillesvangurp/ktsearch/request-dsl.kt +++ b/search-client/src/commonMain/kotlin/com/jillesvangurp/ktsearch/request-dsl.kt @@ -25,8 +25,8 @@ data class SearchAPIRequest( } fun parameter(key: String, value: Duration?) { - value?.let { - parameters[key] = "${value.inWholeSeconds}s" + value.toElasticsearchTimeUnit()?.let { + parameters[key] = it } } diff --git a/search-client/src/commonTest/kotlin/com/jillesvangurp/ktsearch/IndexCreateTest.kt b/search-client/src/commonTest/kotlin/com/jillesvangurp/ktsearch/IndexCreateTest.kt index bdf0ea5d..2737e997 100644 --- a/search-client/src/commonTest/kotlin/com/jillesvangurp/ktsearch/IndexCreateTest.kt +++ b/search-client/src/commonTest/kotlin/com/jillesvangurp/ktsearch/IndexCreateTest.kt @@ -4,6 +4,7 @@ import io.kotest.matchers.shouldBe import kotlinx.coroutines.test.runTest import kotlinx.serialization.json.* import kotlin.test.Test +import kotlin.time.Duration.Companion.seconds class IndexCreateTest: SearchTestBase() { @Test @@ -33,7 +34,7 @@ class IndexCreateTest: SearchTestBase() { settings { replicas = 0 shards = 5 - refreshInterval = "31s" + refreshInterval = 31.seconds } } response.acknowledged shouldBe true diff --git a/search-dsls/src/commonMain/kotlin/com/jillesvangurp/searchdsls/mappingdsl/IndexSettings.kt b/search-dsls/src/commonMain/kotlin/com/jillesvangurp/searchdsls/mappingdsl/IndexSettings.kt index de4d18d7..2a8244a8 100644 --- a/search-dsls/src/commonMain/kotlin/com/jillesvangurp/searchdsls/mappingdsl/IndexSettings.kt +++ b/search-dsls/src/commonMain/kotlin/com/jillesvangurp/searchdsls/mappingdsl/IndexSettings.kt @@ -4,6 +4,7 @@ package com.jillesvangurp.searchdsls.mappingdsl import com.jillesvangurp.jsondsl.* import kotlin.reflect.KProperty +import kotlin.time.Duration @Suppress("LeakingThis") class Analysis : JsonDsl() { @@ -67,7 +68,7 @@ class Analysis : JsonDsl() { class IndexSettings : JsonDsl() { var replicas: Int by property("index.number_of_replicas") var shards: Int by property("index.number_of_shards") - var refreshInterval: String by property("index.refresh_interval") + var refreshInterval: Duration by property("index.refresh_interval") var indexLifeCycleName: String by property("index.lifecycle.name") fun analysis(block: Analysis.() -> Unit) {