I am trying to send message via the CreateAsync function from the NEST API and I get a missing timestamp error
The code I'm using is
var node = new Uri($"{_baseUrl}:{_elasticPort}");
var settings = new ConnectionSettings(node);
settings.BasicAuthentication("user", "pass");
var elasticClient = new ElasticClient(settings);
var elasticResponse = await elasticClient.IndexAsync<Message>(new(_message, DateTime.UtcNow), d =>
{
d.OpType(OpType.Create);
d.Index(_index);
d.Id("id");
return d;
});
Console.WriteLine(elasticResponse);
And the error I'm getting is
Invalid NEST response built from a unsuccessful (400) low level call on PUT: /index-2022.07.24/_doc/id?op_type=create
{
"Error": {
"Headers": {},
"RootCause": [
{
"AdditionalProperties": {},
"BytesLimit": null,
"BytesWanted": null,
"CausedBy": null,
"Column": null,
"FailedShards": [],
"Grouped": null,
"Index": null,
"IndexUUID": null,
"Language": null,
"LicensedExpiredFeature": null,
"Line": null,
"Phase": null,
"Reason": "failed to parse",
"ResourceId": [],
"ResourceType": null,
"Script": null,
"ScriptStack": [],
"Shard": null,
"StackTrace": null,
"Type": "mapper_parsing_exception"
}
],
"AdditionalProperties": {},
"BytesLimit": null,
"BytesWanted": null,
"CausedBy": {
"AdditionalProperties": {},
"BytesLimit": null,
"BytesWanted": null,
"CausedBy": null,
"Column": null,
"FailedShards": [],
"Grouped": null,
"Index": null,
"IndexUUID": null,
"Language": null,
"LicensedExpiredFeature": null,
"Line": null,
"Phase": null,
"Reason": "data stream timestamp field [@timestamp] is missing",
"ResourceId": [],
"ResourceType": null,
"Script": null,
"ScriptStack": [],
"Shard": null,
"StackTrace": null,
"Type": "illegal_argument_exception"
},
"Column": null,
"FailedShards": [],
"Grouped": null,
"Index": null,
"IndexUUID": null,
"Language": null,
"LicensedExpiredFeature": null,
"Line": null,
"Phase": null,
"Reason": "failed to parse",
"ResourceId": [],
"ResourceType": null,
"Script": null,
"ScriptStack": [],
"Shard": null,
"StackTrace": null,
"Type": "mapper_parsing_exception"
},
"Status": 400
}
{
"Message": "Request failed to execute. Call: Status code 400 from: PUT /index-2022.07.24/_doc/id?op_type=create. ServerError: Type: mapper_parsing_exception Reason: \u0022failed to parse\u0022 CausedBy: \u0022Type: illegal_argument_exception Reason: \u0022data stream timestamp field [@timestamp] is missing\u0022\u0022",
"Data": {},
"InnerException": null,
"HelpLink": null,
"Source": null,
"HResult": -2146233088,
"StackTrace": null
}
I tried finding a detailed description of this API or look up a similiar problem, but it seems like the datastreams concept is fairly new and all the related posts are too old.
Edit - I realized I forgot to add the record I'm using to make the message, so:
record Message(string Message, DateTime @timestamp);
EDIT: I evaluated the request with wireshark, it has a timestamp but the item is formatted as timestamp not @timestamp, I can't seem to find an api that allows me to format the name of the item correctly as it is named @timestamp on the record...
Thanks!
CodePudding user response:
For some reason the serializer took out the @ at the beginning of the type name... Adding this line to the settings solved it.
settings.DefaultMappingFor<Message>(m => m.PropertyName(p => p.timestamp, "@timestamp"));