question-mark
Stuck on an issue?

Lightrun Answers was designed to reduce the constant googling that comes with debugging 3rd party libraries. It collects links to all the places you might be looking at while hunting down a tough bug.

And, if you’re still stuck at the end, we’re happy to hop on a call to see how we can help out.

GetDataStreamAsync throws JSON value could not be converted to Elastic.Clients.Elasticsearch.HealthStatus

See original GitHub issue

Elastic.Clients.Elasticsearch version: 8.0.5

Elasticsearch version: 8.6.0

.NET runtime version: 6

Operating system version: macOS Monetery : 12.6.3

Description of the problem including expected versus actual behavior:

After a CreateDataStreamAsync and the process has finished, I re-spin up the process and it executes GetDataStreamAsync which then throws this exception

The JSON value could not be converted to Elastic.Clients.Elasticsearch.HealthStatus. Path: $.data_streams[0].status | LineNumber: 18 | BytePositionInLine: 24.

of type: UnexpectedTransportException

Steps to reproduce:


module EsDataStream =
    let dataStreamExists (getClient: unit -> ElasticsearchClient) (logIndex: string) (cancellationToken: CancellationToken) = task {
        let client = getClient ()
        let dsRequest = GetDataStreamRequest(logIndex)
        let! exists = client.Indices.GetDataStreamAsync(dsRequest, cancellationToken)
        
        return if not exists.IsValidResponse || exists.DataStreams.Count <> 0 then false
                   else exists.DataStreams.Count = 1 // = is equiv to ==
    }
    
    let dataStreamCreate (getClient: unit -> ElasticsearchClient) (logIndex: string) (cancellationToken: CancellationToken) = task {
        let client = getClient ()
        let request = CreateDataStreamRequest(logIndex)
        let! response = client.Indices.CreateDataStreamAsync(request, cancellationToken)
        return response.IsValidResponse && response.Acknowledged
    }

These are used like so:


let! result =
    EsDataStream.dataStreamExists getClient logIndex cancellationToken
    |> Task.bind (fun result ->
        if not result then EsDataStream.dataStreamCreate getClient logIndex cancellationToken
        else Task.FromResult(true))
    
return result

All that function basically does, is if the result from dataStreamExists is false, then it will fire off dataStreamCreate.

The exception gets thrown from the GetDataStreamAsync

Elastic.Transport.UnexpectedTransportException: The JSON value could not be converted to Elastic.Clients.Elasticsearch.HealthStatus. Path: $.data_streams[0].status | LineNumber: 18 | BytePositionInLine: 24. —> System.Text.Json.JsonException: The JSON value could not be converted to Elastic.Clients.Elasticsearch.HealthStatus. Path: $.data_streams[0].status | LineNumber: 18 | BytePositionInLine: 24. at Elastic.Clients.Elasticsearch.ThrowHelper.ThrowJsonException(String message) in //src/Elastic.Clients.Elasticsearch/Core/Exceptions/ThrowHelper.cs:line 14 at Elastic.Clients.Elasticsearch.HealthStatusConverter.Read(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options) in //src/Elastic.Clients.Elasticsearch/Generated/Types/Enums/Enums.NoNamespace.g.cs:line 480 at System.Text.Json.Serialization.JsonConverter1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value) at System.Text.Json.Serialization.Metadata.JsonPropertyInfo1.ReadJsonAndSetMember(Object obj, ReadStack& state, Utf8JsonReader& reader) at System.Text.Json.Serialization.Converters.ObjectDefaultConverter1.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value) at System.Text.Json.Serialization.JsonConverter1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value) at System.Text.Json.Serialization.JsonCollectionConverter2.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, TCollection& value) at System.Text.Json.Serialization.JsonConverter1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value) at System.Text.Json.Serialization.Metadata.JsonPropertyInfo1.ReadJsonAndSetMember(Object obj, ReadStack& state, Utf8JsonReader& reader) at System.Text.Json.Serialization.Converters.ObjectDefaultConverter1.OnTryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value) at System.Text.Json.Serialization.JsonConverter1.TryRead(Utf8JsonReader& reader, Type typeToConvert, JsonSerializerOptions options, ReadStack& state, T& value) at System.Text.Json.Serialization.JsonConverter1.ReadCore(Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state) at System.Text.Json.JsonSerializer.ReadCore[TValue](JsonConverter jsonConverter, Utf8JsonReader& reader, JsonSerializerOptions options, ReadStack& state) at System.Text.Json.JsonSerializer.ReadCore[TValue](JsonReaderState& readerState, Boolean isFinalBlock, ReadOnlySpan1 buffer, JsonSerializerOptions options, ReadStack& state, JsonConverter converterBase) at System.Text.Json.JsonSerializer.ContinueDeserialize[TValue](ReadBufferState& bufferState, JsonReaderState& jsonReaderState, ReadStack& readStack, JsonConverter converter, JsonSerializerOptions options) at System.Text.Json.JsonSerializer.ReadAllAsync[TValue](Stream utf8Json, JsonTypeInfo jsonTypeInfo, CancellationToken cancellationToken) at Elastic.Transport.DefaultResponseBuilder1.SetBodyAsync[TResponse](ApiCallDetails details, RequestData requestData, Stream responseStream, String mimeType, CancellationToken cancellationToken) at Elastic.Transport.DefaultResponseBuilder1.ToResponseAsync[TResponse](RequestData requestData, Exception ex, Nullable1 statusCode, Dictionary2 headers, Stream responseStream, String mimeType, Int64 contentLength, IReadOnlyDictionary2 threadPoolStats, IReadOnlyDictionary2 tcpStats, CancellationToken cancellationToken) at Elastic.Transport.HttpTransportClient.RequestAsync[TResponse](RequestData requestData, CancellationToken cancellationToken) at Elastic.Transport.DefaultRequestPipeline1.CallProductEndpointAsync[TResponse](RequestData requestData, CancellationToken cancellationToken) at Elastic.Transport.DefaultHttpTransport1.RequestAsync[TResponse](HttpMethod method, String path, PostData data, RequestParameters requestParameters, CancellationToken cancellationToken) --- End of inner exception stack trace --- at Elastic.Transport.DefaultHttpTransport1.RequestAsync[TResponse](HttpMethod method, String path, PostData data, RequestParameters requestParameters, CancellationToken cancellationToken) at Elastic.Clients.Elasticsearch.ElasticsearchClient.<>c__DisplayClass32_0`3.<<DoRequestAsync>g__SendRequest|0>d.MoveNext() in //src/Elastic.Clients.Elasticsearch/Client/ElasticsearchClient.cs:line 374 — End of stack trace from previous location — at EsLogging.EsDataStream.dataStreamExists@36.MoveNext()

Expected behavior

What should happen is the response gets serialised properly

Issue Analytics

  • State:closed
  • Created 7 months ago
  • Comments:12 (5 by maintainers)

github_iconTop GitHub Comments

1reaction
stevejgordoncommented, Feb 21, 2023

I agree. In this case, this is an exception in deserialising our type, so it shouldn’t be up to you to debug it. For source-related exceptions, this would be far more valid for debugging. I’ve captured this on our roadmap.

1reaction
stevejgordoncommented, Feb 16, 2023

We do handle this inconsistent casing for HealthStatus in the spec, but the .NET generator doesn’t apply the aliases. We can hopefully solve this by updating the converter code gen for enums to include the aliases when available. We’ll aim to get this fixed in the next release.

Read more comments on GitHub >

github_iconTop Results From Across the Web

IElasticClient.CatHealth() works OK locally, but fails in json ...
Hi gang, Context: ElasticSearch 2.3.4 C#/.Net apps using NEST & Elasticsearch.Net 2.3.3 (next hop is of client nuget package is to 2.4.x ...
Read more >
What's causing JsonException: The JSON value could not ...
I'm working with an API that returns as JSON response. I'm trying to use System.Text.Json to deserialize the JSON response into a class....
Read more >
Failure with sorts and new co.elastic.clients:elasticsearch- ...
I am upgrading from Java High-level REST client 7.15 to the new Java client. I am almost done, it seems only one issue...
Read more >
Cluster health API | Elasticsearch Guide [8.9]
The cluster health API returns a simple status on the health of the cluster. You can also use the API to get the...
Read more >
Springboot ElasticSearch Configuration Error - java
Why this error coming failed to load elasticsearch nodes in spring boot? 1 · Elasticsearch throwing an error during startup · 1 ·...
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found