Skip to content

Floating-point types are not always serialized with a decimal point #7051

Closed
@Alkaersig

Description

@Alkaersig

Elastic.Clients.Elasticsearch version:
8.0.2

Elasticsearch version:
8.5.0

.NET runtime version:
6.0

Operating system version:
Windows 11

Description of the problem including expected versus actual behavior:
Ran into another problem while migrating one of our smaller projects to v8. Trying to index a range of documents i got an error that [float] could not be converted to [long]. Inspecting the request, it turns out that whenever a floating-point value does not have a decimal part, it is serialized as an int (without a decimal point/radix).

I guess this problem was introduced by the new Serializer in the v8 client. This was fixed some years ago back in v7:
#3657

Steps to reproduce:
1: Create a simple document

public class FloatDocument
{
  public decimal Amount { get; set; }
}

2: Insert a range of documents with a mix of integers and decimal numbers:

var data = new List<FloatDocument>();
data.Add(new FloatDocument() { Amount = 11 });
data.Add(new FloatDocument() { Amount = 1.15M });
data.Add(new FloatDocument() { Amount = 3.76M });

await esClient.IndexManyAsync<FloatDocument>(data, "index");

3: Returns an error: mapper [amount] cannot be changed from type [float] to [long]" since it serializes to:

[{
  Amount: 11
},
{
  Amount: 1.15
},
{
  Amount: 3.76
}]

Expected behavior
Floating-point types should always be serialized as floating-point types (serialized with a decimal point).

Metadata

Metadata

Assignees

No one assigned

    Labels

    8.xRelates to a 8.x client version

    Type

    No type

    Projects

    No projects

    Milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions