Skip to content

Commit

Permalink
fix: update alias creation method and url for compatibility
Browse files Browse the repository at this point in the history
Updated the REST API method for creating aliases from PUT to POST and changed the URL from
`_aliases/<alias_name>` to `_aliases` to align with OpenSearch v2.17 requirements.
  • Loading branch information
jboix committed Nov 28, 2024
1 parent b67f462 commit b2e20f0
Show file tree
Hide file tree
Showing 2 changed files with 5 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -48,7 +48,7 @@ class AliasSetupTask(
/**
* Path to create the alias in OpenSearch.
*/
private const val ALIAS_CREATION_PATH = "/_aliases/${ALIAS_NAME}"
private const val ALIAS_CREATION_PATH = "/_aliases"
}

/**
Expand Down Expand Up @@ -76,7 +76,7 @@ class AliasSetupTask(
private fun createAlias(): Mono<*> {
val indexTemplateJson = resourceLoader.loadResourceContent("classpath:opensearch/alias.json")
return webClient
.put()
.post()
.uri(ALIAS_CREATION_PATH)
.header(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE)
.bodyValue(indexTemplateJson)
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -60,7 +60,7 @@ class AliasSetupTaskTest(
createDispatcher(
mapOf(
"GET" to "/_alias/user_events" to MockResponse().setResponseCode(404),
"PUT" to "/_aliases/user_events" to MockResponse().setResponseCode(201),
"POST" to "/_aliases" to MockResponse().setResponseCode(201),
),
)

Expand All @@ -76,8 +76,8 @@ class AliasSetupTaskTest(
}

mockWebServer.takeRequest().apply {
path shouldBe "/_aliases/user_events"
method shouldBe "PUT"
path shouldBe "/_aliases"
method shouldBe "POST"
shouldNotThrow<Exception> { objectMapper.readTree(body.readUtf8()) }
}
}
Expand Down

0 comments on commit b2e20f0

Please sign in to comment.