elastic / elasticsearch-java

Official Elasticsearch Java Client
Apache License 2.0
412 stars 239 forks source link

Should `ElasticsearchIndicesClient#existsIndexTemplate()` with invalid credentials return `false` or `ElasticsearchException(security_exception, 401)` #212

Open cyrille-leclerc opened 2 years ago

cyrille-leclerc commented 2 years ago

Java API client version

8.1.0

Java version

openjdk version "11.0.11" 2021-04-20 OpenJDK Runtime Environment AdoptOpenJDK-11.0.11+9 (build 11.0.11+9) OpenJDK 64-Bit Server VM AdoptOpenJDK-11.0.11+9 (build 11.0.11+9, mixed mode)

Elasticsearch Version

8.1.0

Problem description

ElasticsearchIndicesClient#existsIndexTemplate() with invalid credentials returns false when I expected the returned valued to be an ElasticsearchException(security_exception, 401) that would have been consistent with the returned value of methods like ElasticsearchIlmClient#getLifecycle().

Could you please clarify the expected behaviour? I expected an ElasticsearchException(security_exception, 401) and got surprised.

See https://github.com/jenkinsci/opentelemetry-plugin/blob/opentelemetry-2.3.0-rc1/src/main/java/io/jenkins/plugins/opentelemetry/backend/elastic/ElasticsearchLogStorageRetriever.java#L218-L243

swallez commented 2 years ago

This is actually a bug related to the fact that this is a HEAD request that doesn't return a JSON error reponse. We have to create the error response in the client in this case.