Skip to content

Unable to serialize double value #7757

@h-h-

Description

@h-h-

Elastic.Clients.Elasticsearch version: 8.1.1

Elasticsearch version: 8.7.1

.NET runtime version: .NET FW 4.7.2

Operating system version: Win10 22H2

Description of the problem including expected versus actual behavior:
Cannot index an instance of a class containing a public property of type double.
Elastic.Transport.UnexpectedTransportException: Unable to serialize double value.

Steps to reproduce:

  1. Execute following code/unit test:
using System;
using System.Diagnostics;
using Elastic.Clients.Elasticsearch;
using Elastic.Transport;
using Xunit;

namespace SearchESSequenceResearch.V1
{
	public class MyDecimalClass
	{
		public decimal MyDecimal { get; set; }
	}

	public class MyDoubleClass
	{
		public double MyDouble { get; set; }
	}

	public class TestIndexDouble
	{
		private const string TestMachineUriString = "https://docker.mydomain.com:9280"; // ES 8 in docker
		private readonly Uri _testMachineUri = new Uri(TestMachineUriString);

		[Fact]
		public void TestIndexingDouble()
		{
			ElasticsearchClient client = GetClient();
			var decimalInstance = new MyDecimalClass
			{
				MyDecimal = 123.45m
			};
			try
			{
				client.Index(decimalInstance, "mytestindex");
			}
			catch (Exception e)
			{
				Debug.WriteLine(e);
				throw;
			}
			
			var doubleInstance = new MyDoubleClass
			{
				MyDouble = 123.45d
			};
			try
			{
				client.Index(doubleInstance, "mytestindex");
			}
			catch (Exception e)
			{
				Debug.WriteLine(e);
				throw;
			}
			
		}

		private ElasticsearchClient GetClient()
		{
			var settings = new ElasticsearchClientSettings(_testMachineUri)
				.Authentication(new BasicAuthentication("elastic", "passwordhere"))
				.ServerCertificateValidationCallback((o, cert, chain, errors) => true);
			settings.DisableDirectStreaming();
			var client = new ElasticsearchClient(settings);
			return client;
		}
	}
}```

**Expected behavior**
The item should be serialized and addet to the index.

**Provide `DebugInformation` (if relevant)**:
Elastic.Transport.UnexpectedTransportException: Unable to serialize double value.

Elastic.Transport.UnexpectedTransportException
Unable to serialize double value.
   bei Elastic.Transport.DefaultHttpTransport`1.ThrowUnexpectedTransportException[TResponse](Exception killerException, List`1 seenExceptions, RequestData requestData, TResponse response, RequestPipeline pipeline) in /home/runner/work/elastic-transport-net/elastic-transport-net/src/Elastic.Transport/DefaultHttpTransport.cs:Zeile 328.
   bei Elastic.Transport.DefaultHttpTransport`1.Request[TResponse](HttpMethod method, String path, PostData data, RequestParameters requestParameters) in /home/runner/work/elastic-transport-net/elastic-transport-net/src/Elastic.Transport/DefaultHttpTransport.cs:Zeile 176.
   bei Elastic.Clients.Elasticsearch.ElasticsearchClient.DoRequest[TRequest,TResponse,TRequestParameters](TRequest request, Action`1 forceConfiguration) in /_/src/Elastic.Clients.Elasticsearch/Client/ElasticsearchClient.cs:Zeile 217.

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