java.sql.Timestamp => ElasticSearch long => C# System.DateTime

I use java.sql.Timestamp
2014-12-27 00:00:00

and ElasticSearch saves it as 1419634800000

"EventDateLocal" : {
     "type" : "long"

and I want to read it in C# (via NEST) in DateTime

I tried

[Date(NumericResolution = NumericResolutionUnit.Milliseconds)]  ?????
public DateTime? EventDateLocal { get; set; }

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))
	  .DefaultTypeNameInferrer(t => type)

If not with annotation is it possible somehow to tell NEST about long saved?

client.Map<Event>(m => m
  .Properties(ps => ps
	  .Date(e => e

Does the epoch_millis format do what you need?

Hmm this could work but Is there any way to tell serializer that it should expect long instead of string,
I don't know where to put that code (accessors get/set of field or anotation)?

And I'am not allowed to change mappings or anything in ES-db (read-only) I just want to specify different way of reading their longs

Hmm that's a problem. I'd open an issue on the .NET client GitHub repo, because you are technically supposed to be able to store and read longs as epoch_millis. There might be some supported way of doing it that I'm not aware of, they'll know better :slight_smile:

You might have to fall back to your original approach afterall with a custom DateTime serialiser that deserialises a long to unix millis like this SO question.

Yep thanks, man answered yesterday. =D