elastic/elasticsearch-net

[Elastic.Clients.Elasticsearch 9.0.7] Invalid media-type error when indexing or querying with Elasticsearch 8.13.x

Closed this issue · 2 comments

[Elastic.Clients.Elasticsearch 9.0.7] Invalid media-type value on headers [Content-Type, Accept] when using ES 8.13.x

Elastic.Clients.Elasticsearch version: 9.0.7

Elasticsearch version: 8.13.4 (Docker)

.NET runtime version: .NET 9 — also tested with .NET 8

Operating system version: Windows 11 + Linux (Docker container)

Description of the problem including expected versus actual behavior:

When using Elastic.Clients.Elasticsearch v9.0.7 to interact with an Elasticsearch 8.13.4 cluster, all operations like IndexAsync, SearchAsync, and PingAsync fail with the following error:

Invalid media-type value on headers [Content-Type, Accept]

Expected behavior: the client should send the appropriate headers (Content-Type: application/vnd.elasticsearch+json;compatible-with=8) automatically or provide a way to configure them.

Steps to reproduce:

  1. Use Elastic.Clients.Elasticsearch v9.0.7
  2. Connect to an Elasticsearch 8.13.4 cluster
  3. Try to run IndexAsync or SearchAsync
  4. Observe the media-type header error

Expected behavior

All operations should succeed if Elasticsearch is reachable. The client should default to setting proper Accept and Content-Type headers or expose a configuration API (like .DefaultMimeType(...)).

Provide ConnectionSettings:

var settings = new ElasticsearchClientSettings(new Uri("http://elasticsearch:9200"))
    .DefaultIndex("logservice-logs")
    .DefaultFieldNameInferrer(p => p.ToLowerInvariant())
    .DisableDirectStreaming()
    .EnableDebugMode()
    .PrettyJson();

Provide DebugInformation:

Elastic write failed: Log yazılamadı., Invalid media-type value on headers [Content-Type, Accept]
Elastic query failed: Invalid media-type value on headers [Content-Type, Accept]
HealthCheck failed: elastic_ping_check → Unhealthy (Invalid media-type header)

Hi @berkayhuz ,

please check the "Versioning" section in the README.

Using a 9.x client to talk to a 8.x server is not supported.

Hacking the content-type/accept headers for this purpose is as well nothing we want our users to do easily since it will cause unforeseen problems at some point.

If you really want to go that route, you can override the headers on a per request basis. Please search the closed issues; this has been discussed a few times already.

Note that you won't receive any official support in this case.

My personal recommendation, if you don't use any of the new Elasticsearch 9 features, is to wait for the 8.19.0 GA client release. This one can be used to talk to 8.x and 9.x servers and has the same new API surface and improvements as the 9.x client.

Hi @flobernd,

Thank you for the clear explanation and guidance.

Your clarification regarding the 9.x client’s compatibility with 8.x servers was very helpful.

Appreciate your time, and thank you again for your contributions to the client library.