Skip to content

Search response - deserialization of numbers (int, double) #7912

@zsonglorman

Description

@zsonglorman

Elastic.Clients.Elasticsearch version: 8.9.0

Elasticsearch version: 8.8.1

.NET runtime version: 6.0

Operating system version: Windows 10

Description of the problem including expected versus actual behavior:
Number data types in search response hits source are lost (whether it is a double, int, etc.)

Steps to reproduce:

  1. Create index with the following mappings:
"category": {
  "type": "keyword"
},
"availabilityValue": {
  "type": "integer"
},
"dimension": {
  "type": "double"
}
  1. Upload some documents
  2. Execute search request: var result = client.SearchAsync<Dictionary<string, object>>(request);

In the older NEST client, the response hits source contained all fields in their respective data types, so it was easy to use them i.e.:

result.Hits.First().Source["category"].GetType().Name -> String
result.Hits.First().Source["availabilityValue"].GetType().Name -> Int32
result.Hits.First().Source["dimension"].GetType().Name -> Double

However, in the new Elastic.Clients.Elasticsearch client, these hit sources are JsonElements, where type of number is lost:
result.Hits.First().Source["category"] -> ValueKind = String
result.Hits.First().Source["availabilityValue"] -> ValueKind = Number
result.Hits.First().Source["dimension"] -> ValueKind = Number

For the 2 numbers, the information whether it was originally a double or int is lost, so we are unable to decide whether to call GetInt32 or GetDouble on the json element to get its value.

I'm not sure whether it's a bug, or there's a solution to our problem that we are not aware of.
Thank you in advance!

Metadata

Metadata

Assignees

No one assigned

    Labels

    8.xRelates to a 8.x client version

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions