I use Serilog and the ElasticSearch Sink with AutoRegisterTemplate = true
That stores the following in ElasticSearch
{
"@timestamp": "2016-08-17T08:57:37.3487446+02:00",
"level": "Information",
"messageTemplate": "User login {UserId}",
"message": "User login ...,
"fields": {
"UserId": "...",
"ProcessId": 15568,
"ThreadId": 14,
"MachineName": "...",
"EnvironmentUserName": "...",
"HttpRequestId": "...",
"HttpRequestClientHostIP": "::1",
"HttpRequestType": "POST",
"Version": "1.0.0.0"
}
}
I can query the index with DynamicResponse
var searchResponse = client.Search<DynamicResponse>(s => s
.Index("logstash-*")
.AllTypes()
.Size(50)
.Query(q => q.Bool(b => b.Must(bs => bs.Term(p => p.Field("fields.UserId.raw").Value("..."))))
)
);
But I would like to use a strongly typed class for the result.
I have tried with the following class.
public class LogResponse
{
public string Message { get; set; }
[Date(Name = "@timestamp")]
public DateTime Timestamp { get; set; }
public LogResponseFields Fields { get; set; }
public class LogResponseFields
{
public Guid UserId { get; set; }
}
}
But the timestamp is not set, it defaults to DateTime.Min, both Message and UserId are mapped correctly.
How to I map the @timestamp field?