Skip to content

Esql.QueryAsObjectsAsync<TDocument> throws a serialization exception: The element cannot be an object or array, if TDocument contains an array #8456

Open
@AlexanderEklf

Description

@AlexanderEklf

Elastic.Clients.Elasticsearch version: 8.17.1

Elasticsearch version: 8.17.1

.NET runtime version: 9

Operating system version: Windows 11

Description of the problem including expected versus actual behavior:
Esql.QueryAsObjectsAsync<TDocument> throws a serialization exception: The element cannot be an object or array, if TDocument contains an array.

Steps to reproduce:

  1. docker run -d --name elasticsearch --net elastic -p 9200:9200 -p 9300:9300 -e "discovery.type=single-node" -e "xpack.security.enabled=false" elasticsearch:8.17.1
  2. run sample code
using Elastic.Clients.Elasticsearch;

var searchClient = new ElasticsearchClient(
   new ElasticsearchClientSettings(new Uri("http://localhost:9200")).DefaultMappingFor<Person>(c =>
       c.IndexName("persons")
   )
);

if ((await searchClient.Indices.ExistsAsync<Person>()).Exists)
{
   await searchClient.Indices.DeleteAsync<Person>();
}

var createResp = await searchClient.Indices.CreateAsync<Person>();

var indexRes = await searchClient.IndexAsync(new Person { Id = 0, Values = [1, 2, 3] });

Thread.Sleep(5000);

var result = await searchClient.Esql.QueryAsObjectsAsync<Person>(q => q.Query("FROM persons"));

foreach (var item in result.ToArray())
{
   Console.WriteLine(item.Id);
}

public class Person
{
   public int Id { get; set; }
   public int[] Values { get; set; } = [];
}
  1. Exception is thrown
Exception has occurred: CLR/System.InvalidOperationException
An exception of type 'System.InvalidOperationException' occurred in System.Text.Json.dll but was not handled in user code: 'The element cannot be an object or array.

Expected behavior
The response from Esql.QueryAsObjects<TDocument> should successfully map to type Person.

Metadata

Metadata

Assignees

No one assigned

    Labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions