I use java.sql.Timestamp
2014-12-27 00:00:00
and ElasticSearch
saves it as long 1419634800000
with mapping:
"EventDateLocal" : {
"type" : "long"
}
and I want to read it in C# (via NEST) in System.DateTime
I tried
[Date(NumericResolution = NumericResolutionUnit.Milliseconds)]
public DateTime? EventDateLocal { get; set; }
but I got:
Unhandled Exception: Elasticsearch.Net.UnexpectedElasticsearchClientException: U
nexpected token parsing date. Expected String, got Integer.
....
Path 'hits.hits[0]._
source.EventDateLocal', line 1, position 350. ---> Newtonsoft.Json.JsonSerializa
tionException: Unexpected token parsing date. Expected String, got Integer. Path
'hits.hits[0]._source.EventDateLocal', line 1, position 350.
at Newtonsoft.Json.Converters.IsoDateTimeConverter.ReadJson(JsonReader reader
, Type objectType, Object existingValue, JsonSerializer serializer)
at Newtonsoft.Json.Serialization.JsonSerializerInternalReader.DeserializeConv
ertable(JsonConverter converter, JsonReader reader, Type objectType, Object exis
tingValue)...
What should I put in annotation to get this effect automatically (long + unix => EventDate) :
foreach (var e in request.Documents)
{
var start = new DateTime(1970, 1, 1, 0, 0, 0, DateTimeKind.Utc);
var date = start.AddMilliseconds(e.EventDateLocal.Value).ToLocalTime();
}
My NEST configuration is:
var client = new ElasticClient(new ConnectionSettings(new Uri(url))
.DefaultIndex(index)
.DefaultTypeNameInferrer(t => type)
);
If not with annotation is it possible somehow to tell NEST about the long?
client.Map<Event>(m => m
.AutoMap()
.Properties(ps => ps
.Date(e => e
.Name("EventDateLocal")
.Format(????)
)
)
);