How to map C# DateTime property to @timestamp field

I am trying unsuccessfully to se the c# client to bluk insert data into elasticsearch. the client connects successfully, however I now have an issue with the following code:

var settings = client.ElasticsearchClientSettings;

settings.DefaultIndices.Add(typeof(HardwareData), "metrics-hardware-pristem");
var data = new HardwareData
{
    Id = 1,
    System_ErrorLevel = 1,
    timestamp = DateTime.Now
};
var timestampMemberInfo = typeof(HardwareData).GetMember("timestamp")[0];
client.ElasticsearchClientSettings.PropertyMappings.Add(timestampMemberInfo,
    new PropertyMapping() { Name = "@timestamp" });

var r2 = await client.IndexAsync(new IndexRequest<HardwareData>()
{
    Document = data
});
Console.WriteLine($"success={r2.IsSuccess()} : {r2.Id} => {r2.Result},{r2.DebugInformation}");

The output of DebugInformation is:

{"type":"illegal_argument_exception","reason":"data stream timestamp field [@timestamp] is missing"}},"status":400}

From what I see there is lots of documentation on the NEST api, but very little on the current api, I was unable to find a working example.

What is the easiest way to map a property to a field (particularly the timestamp, since others should map automatically because they have the same name, I cannot use @timestamp as the name) ?

Additionally I tried using json attributes on the HardwareData class to specify the mapping, but that also failed with the same error.

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.