Elasticsearch.Net.UnexpectedElasticsearchClientException: expected:'{', actual:'[', at offset:13520

Hello I am updating a project to a the new NEST version: 7.17
But keep getting this error from the logging:

Elasticsearch.Net.UnexpectedElasticsearchClientException: expected:'{', actual:'[', at offset:13520
 ---> Elasticsearch.Net.Utf8Json.JsonParsingException: expected:'{', actual:'[', at offset:13520
   at Elasticsearch.Net.Utf8Json.JsonReader.ReadIsBeginObjectWithVerify()
   at Deserialize(Object[] , JsonReader& , IJsonFormatterResolver )
   at Deserialize(Object[] , JsonReader& , IJsonFormatterResolver )
   at Nest.SourceFormatter`1.Deserialize(JsonReader& reader, IJsonFormatterResolver formatterResolver)
   at Deserialize(Object[] , JsonReader& , IJsonFormatterResolver )
   at Nest.ReadAsFormatter`2.Deserialize(JsonReader& reader, IJsonFormatterResolver formatterResolver)
   at Elasticsearch.Net.Utf8Json.Formatters.CollectionFormatterBase`4.Deserialize(JsonReader& reader, IJsonFormatterResolver formatterResolver)
   at Deserialize(Object[] , JsonReader& , IJsonFormatterResolver )
   at Nest.ReadAsFormatter`2.Deserialize(JsonReader& reader, IJsonFormatterResolver formatterResolver)
   at Deserialize(Object[] , JsonReader& , IJsonFormatterResolver )
   at Elasticsearch.Net.Utf8Json.JsonSerializer.Deserialize[T](Byte[] bytes, Int32 offset, IJsonFormatterResolver resolver)
   at Elasticsearch.Net.Utf8Json.JsonSerializer.DeserializeAsync[T](Stream stream, IJsonFormatterResolver resolver)
   at Elasticsearch.Net.ResponseBuilder.SetBodyAsync[TResponse](ApiCallDetails details, RequestData requestData, Stream responseStream, String mimeType, CancellationToken cancellationToken)
   at Elasticsearch.Net.ResponseBuilder.ToResponseAsync[TResponse](RequestData requestData, Exception ex, Nullable`1 statusCode, IEnumerable`1 warnings, Stream responseStream, String productName, String mimeType, CancellationToken cancellationToken)
   at Elasticsearch.Net.HttpConnection.RequestAsync[TResponse](RequestData requestData, CancellationToken cancellationToken)
   at Elasticsearch.Net.RequestPipeline.CallElasticsearchAsync[TResponse](RequestData requestData, CancellationToken cancellationToken)
   at Elasticsearch.Net.Transport`1.RequestAsync[TResponse](HttpMethod method, String path, CancellationToken cancellationToken, PostData data, IRequestParameters requestParameters)

Have been searching for a fix but nothing has helped me so far.
Can anyone give some advice?

Im also getting this Error in my code,

Scroll = {"Unable to cast object of type 'System.TimeSpan' to type 'Nest.Time'."}

I already looked at my objects that are being serialized and there aren't any TimeSpan's in my object..

Hi @LhamoDev. Can you share your code for the request that triggers the exception? It looks like something in the response is coming back as an array rather than an object, so this may be a bug in the response model.

Hi @stevejgordon ,
This is the piece that doesn't work,

 if (numberofresults < int.MaxValue)
                {
                    query.From = (page * numberofresults);
                    query.Size = numberofresults;

                    var reservations = await Repository.ElasticClient.SearchAsync<Reservation>(query);
                    return new ESGetReservationsResponse()
                    {
                        Total = Convert.ToInt32(reservations.Total),
                        Reservations = await RetrieveEntireReservations(reservations.Documents, propertyID),
                        Success = true
                    };
                }

It works when The From is 0 and the Size is 15,
But from "Fom = 15" to upper numbers, it doesn't work..

Thanks, @LhamoDev. My best guess is that your Reservation type doesn't align with one of the hits coming back after the 15th document. Is it possible one of the documents includes an array of values where the corresponding property on your Reservation class expects an object? As your size is small, I'd recommend running the same query in Kibana to view the hits and see if any fields hold an array. You could alternatively use a tool such as Fiddler to inspect the response. You could also consider experimenting with From = 15, Size = 1, moving forward until you find a particular hit which causes the exception to be thrown.

1 Like

I'll try that,
Thanks for the feedback :slight_smile:

Hi @stevejgordon
I've tested it like you said, The first 15 Reservations can be retrieved and displayes the correct way,
But when I want to go to Page 2,
It doesn't work anymore, only if I do this:

                 if(page == 1)
                    {
                        query.From = 15;
                        query.Size = 1;
                    }

the first one can be displayed, but when I set the Size to 2 or the From to 16,
It doesn't retrieve anything.
(page property is an array so thats why the if statement says if(page == 1))
Any ideas?
I already serialized the request to json, to see if it's valid or not, and it's valid.
So I really don't know what the issue could be here..
Any ideas?

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.