ransportException: Expecting JSON data but response content-type is application/octet-stream (Elastic Cloud 8.12)

Hello,

I'm encountering a co.elastic.clients.transport.TransportException with the following error message:

co.elastic.clients.transport.TransportException: node: http://my-elasticsearch-project-c2b746.es.ap-southeast-1.aws.elastic.cloud:443/, status: 400, [es/index] Expecting JSON data but response content-type is: application/octet-stream

Environment Details:

  • Elasticsearch Java Client Version: 8.12
  • Spring Data Elasticsearch Version: 4.3.3
  • Elasticsearch Server Version (AWS Elastic Cloud): I am using the default version of Elastic Cloud.
  • Elasticsearch Cloud TLS enabled: I am using the default Elastic cloud configuration.
  • Network Environment: I am using the default Elastic cloud configuration.

Configuration:

My Elasticsearch configuration is as follows:

@Configuration
class ElasticSearchConfig(
    @Value("\${elasticsearch.api}") private val elasticsearchApiKey: String,
    @Value("\${elasticsearch.url}") private val elasticsearchUrl: String,
) : ReactiveElasticsearchConfiguration() {
    override fun clientConfiguration(): ClientConfiguration {
        val client =  ClientConfiguration.create(elasticsearchUrl).apply {
            defaultHeaders.add(HttpHeaders.AUTHORIZATION, "ApiKey $elasticsearchApiKey")
        }
        return client
    }
}

My application.properties file contains:

elasticsearch.url=my-elasticsearch-project-c2b746.es.ap-southeast-1.aws.elastic.cloud:443

Problem:

Indexing Code

elasticsearchClient.index { it.index("product").document(product) }.id()

Index Mapping

@Document(indexName = "product", createIndex = true)
@Setting(settingPath = "settings.json")
data class Product(
    @Field(type = FieldType.Keyword) var name: String,
    @Field(type = FieldType.Text, analyzer = "synonym_analyzer") val description: String,
    @Field(type = FieldType.Keyword) var categories: List<String> = listOf(),
    @Field(type = FieldType.Keyword) var tags: List<String> = listOf(),
)

Could anyone provide insight into why I'm receiving this application/octet-stream error and how to resolve it?

Thank you for your assistance.

Hello and welcome!
Considering I'm not familiar with Spring Data, I think it's unlikely that an endpoint such as index is returning non json data, so my best bet here is that the url used to connect to the elasticsearch instance is wrong, and it's returning some non json error that the client cannot parse. Could you make sure you're using the correct url? You can try following the AWS guide, and if there's nothing new there then there's a similar solved discussion.