POST discuss-time/_doc
{
"mydate" : "2022-05-15T05:49:00-08:00"
}
POST discuss-time/_doc
{
"mydate" : "2022-05-15T06:49:00-08:00"
}
POST discuss-time/_doc
{
"mydate" : "2022-05-15T07:49:00-08:00"
}
GET discuss-time/_search
{
"_source": ["mydate"],
"fields": ["*"]
}
Results notice the difference between the source field and the stored field which is in UTC
{
"took" : 0,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 3,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "discuss-time",
"_type" : "_doc",
"_id" : "Ygc5yIAB5xx3K-gmvcWc",
"_score" : 1.0,
"_source" : {
"mydate" : "2022-05-15T05:49:00-08:00"
},
"fields" : {
"mydate" : [
"2022-05-15T13:49:00.000Z"
]
}
},
{
"_index" : "discuss-time",
"_type" : "_doc",
"_id" : "Ywc5yIAB5xx3K-gmvcW9",
"_score" : 1.0,
"_source" : {
"mydate" : "2022-05-15T06:49:00-08:00"
},
"fields" : {
"mydate" : [
"2022-05-15T14:49:00.000Z"
]
}
},
{
"_index" : "discuss-time",
"_type" : "_doc",
"_id" : "ZAc5yIAB5xx3K-gmvcXl",
"_score" : 1.0,
"_source" : {
"mydate" : "2022-05-15T07:49:00-08:00"
},
"fields" : {
"mydate" : [
"2022-05-15T15:49:00.000Z"
]
}
}
]
}
}
Now the Aggs... max
will return in UTC
GET discuss-time/_search
{
"_source": ["mydate"],
"fields": ["*"],
"query": {
"match_all": {}
},
"aggs": {
"lastfiledate": {
"max": {
"field": "mydate"
}
}
}
}
Results
{
"took" : 1,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 3,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "discuss-time",
"_type" : "_doc",
"_id" : "Ygc5yIAB5xx3K-gmvcWc",
"_score" : 1.0,
"_source" : {
"mydate" : "2022-05-15T05:49:00-08:00"
},
"fields" : {
"mydate" : [
"2022-05-15T13:49:00.000Z"
]
}
},
{
"_index" : "discuss-time",
"_type" : "_doc",
"_id" : "Ywc5yIAB5xx3K-gmvcW9",
"_score" : 1.0,
"_source" : {
"mydate" : "2022-05-15T06:49:00-08:00"
},
"fields" : {
"mydate" : [
"2022-05-15T14:49:00.000Z"
]
}
},
{
"_index" : "discuss-time",
"_type" : "_doc",
"_id" : "ZAc5yIAB5xx3K-gmvcXl",
"_score" : 1.0,
"_source" : {
"mydate" : "2022-05-15T07:49:00-08:00"
},
"fields" : {
"mydate" : [
"2022-05-15T15:49:00.000Z"
]
}
}
]
},
"aggregations" : {
"lastfiledate" : {
"value" : 1.65262974E12,
"value_as_string" : "2022-05-15T15:49:00.000Z"
}
}
}
Now with your formatting ... its the same
GET discuss-time/_search
{
"_source": ["mydate"],
"fields": ["*"],
"query": {
"match_all": {}
},
"aggs": {
"lastfiledate": {
"max": {
"field": "mydate",
"format": "yyyy-MM-dd HH:mm:ss"
}
}
}
}
REsults
{
"took" : 7,
"timed_out" : false,
"_shards" : {
"total" : 1,
"successful" : 1,
"skipped" : 0,
"failed" : 0
},
"hits" : {
"total" : {
"value" : 3,
"relation" : "eq"
},
"max_score" : 1.0,
"hits" : [
{
"_index" : "discuss-time",
"_type" : "_doc",
"_id" : "Ygc5yIAB5xx3K-gmvcWc",
"_score" : 1.0,
"_source" : {
"mydate" : "2022-05-15T05:49:00-08:00"
},
"fields" : {
"mydate" : [
"2022-05-15T13:49:00.000Z"
]
}
},
{
"_index" : "discuss-time",
"_type" : "_doc",
"_id" : "Ywc5yIAB5xx3K-gmvcW9",
"_score" : 1.0,
"_source" : {
"mydate" : "2022-05-15T06:49:00-08:00"
},
"fields" : {
"mydate" : [
"2022-05-15T14:49:00.000Z"
]
}
},
{
"_index" : "discuss-time",
"_type" : "_doc",
"_id" : "ZAc5yIAB5xx3K-gmvcXl",
"_score" : 1.0,
"_source" : {
"mydate" : "2022-05-15T07:49:00-08:00"
},
"fields" : {
"mydate" : [
"2022-05-15T15:49:00.000Z"
]
}
}
]
},
"aggregations" : {
"lastfiledate" : {
"value" : 1.65262974E12,
"value_as_string" : "2022-05-15 15:49:00"
}
}
}