Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

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

Open
AlexanderEklf opened this issue Feb 7, 2025 · 0 comments
Labels
8.x Relates to 8.x client version Category: Bug

Comments

@AlexanderEklf
Copy link

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.

@AlexanderEklf AlexanderEklf added 8.x Relates to 8.x client version Category: Bug labels Feb 7, 2025
@AlexanderEklf AlexanderEklf changed the title Esql.QueryAsObjectsAsync<TDocument>` throws a serialization exception: The element cannot be an object or array, if TDocument contains an array Esql.QueryAsObjectsAsync<TDocument> throws a serialization exception: The element cannot be an object or array, if TDocument contains an array Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
8.x Relates to 8.x client version Category: Bug
Projects
None yet
Development

No branches or pull requests

1 participant