jillesvangurp / kt-search

Multi platform kotlin client for Elasticsearch & Opensearch with easily extendable Kotlin DSLs for queries, mappings, bulk, and more.
MIT License
95 stars 23 forks source link

[BUG] Delete index fails silently #105

Closed barbulescu closed 5 months ago

barbulescu commented 5 months ago

Describe the bug

Delete index failures are ignored as response from HTTP delete status is not checked.

To Reproduce

class DeleteIndexTest : SearchTestBase() {

    @Test
    fun deleteFailsWhenIndexIsNotAvailable() = coRun {
        val indexName = randomIndexName()
        val exception = shouldThrow<RestException> {
            client.deleteIndex(indexName)
        }
        exception.status shouldBe 404
        exception.message shouldContain  "index_not_found_exception"
    }
}

Expected behavior

HTTP status should be checked and exception thrown if it is not success.

On the ES docs the default behaviour is to fail, but this can be changed by setting ignore_unavailable to true.

Your context

Will you be able to help with a pull request?

Yes. Should we check status on RestClient.doRequest and throw RestException on failure?

jillesvangurp commented 5 months ago

Nice catch. There may be more places in the code where things could fail. Might be something that we can generalize with an interface and extension function perhaps?