A simple 2D array (aka multi-dimensional array) for a linestring such as this fails to serialize into json:
new[,]
{
{ 10.0, 10.0 },
{15.0, 15.0 }
}
With the exception message
Elastic.Transport.UnexpectedTransportException: 'Serialization and deserialization of 'System.Double[,]' instances is not supported. Path: $.Coordinates.'
This seems odd that geojson support has disappeared all of a sudden, as that was a main reason for choosing this DB many years ago. Not everyone uses Elasticsearch just for storing logs.
Reading up on the issue this seems to be because System.Text.Json is now being used, and that doesn't support 2d arrays according to Microsoft documentation, so we effectively lost functionality.
What is now a good way of proceeding to use v 8.13 of the dotnet client for geojson data?
Full Program.cs as a demo of the issue
using Elastic.Clients.Elasticsearch;
using Elastic.Transport;
namespace Testing
{
internal class Program
{
static async Task Main(string[] args)
{
var settings = new ElasticsearchClientSettings(new Uri("http://localhost:9200"))
.Authentication(new BasicAuthentication("elastic", "Too4Strong"));
var client = new ElasticsearchClient(settings);
var line = new Line
{
Type = "LineString",
Coordinates = new[,]
{
{ 10.0, 10.0 },
{15.0, 15.0 }
}
};
await client.Indices.CreateAsync("testing");
var result = await client.IndexAsync(line, (IndexName)"testing");
}
}
public record Line
{
public required string Type { get; set; }
public required double[,] Coordinates { get; set; }
}
}