My date histogram query returns something like this:
"facets": {
"hist": {
"_type": "date_histogram",
"entries": [
{
"time": 1385856000000,
"count": 1884
},
{
"time": 1385942400000,
"count": 1902
},
How can I take that time value and get a date string: '2014-02-16'?
Here's what I have so far:
def getFiletime(dt):
microseconds = int(dt) / 10
seconds, microseconds = divmod(microseconds, 1000000)
days, seconds = divmod(seconds, 86400)
return datetime.datetime(1601, 1, 1) + datetime.timedelta(days, seconds, microseconds)
I get back:
1601-01-02 14:37:23.520000
1601-01-02 14:37:32.160000
1601-01-02 14:37:40.800000
1601-01-02 14:37:49.440000
1601-01-02 14:37:58.080000
1601-01-02 14:38:06.720000
1601-01-02 14:38:15.360000
Any ideas? I just copied the getFiletime function from the internet. I don't think it's meant for what I'm doing, but I know it's on the right track. I tried putting the "format" specifier in my elastic search query but that doesn't return the timestamp as a string like the documentation states. Any help would be appreciated and thank you for reading!