I have following mappings:
{
"mappings": {
"properties" : {
"CompletionTime" : {
"type" : "date",
"format": "date_hour_minute_second",
"fields" : {
"keyword" : {
"type" : "date"
}
}
},
"Description" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"InitiatorName" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"StartTime" : {
"type" : "date",
"format": "date_hour_minute_second",
"fields" : {
"keyword" : {
"type" : "date"
}
}
},
"TargetObjectName" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
},
"TargetObjectType" : {
"type" : "text",
"fields" : {
"keyword" : {
"type" : "keyword",
"ignore_above" : 256
}
}
}
}
}
}
I created following code for C# Nest client:
public DateTime GetNewestDocumentDate()
{
var searchResponse = this.ec.Client.Search<Record>(s => s
.Query(q => q.MatchAll())
.Sort(so => so
.Field(fs => fs
.Field("StartTime")
.Order(SortOrder.Descending)
))
.Size(1)
);
var a = searchResponse.Documents;
Console.WriteLine(JsonSerializer.Serialize(a));
return a.StartTime;
}
I am new with C# and Elastic so I don't know how to return document field. In my case it should be something like this, but my syntax is not correct. var a
is an array and a[0].StartTime didn't pass check in Visual Studio.