For datastreams you can use the following API call to collect the maximum timestamp metrics.
GET _data_stream/_stats
Response:
{
"_shards": {
"total": 468,
"successful": 390,
"failed": 0
},
"data_stream_count": 93,
"backing_indices": 345,
"total_store_size_bytes": 41258764754,
"data_streams": [
{
"data_stream": "my-data-stream",
"backing_indices": 3,
"store_size_bytes": 20472,
"maximum_timestamp": 1752188400000 <--- Time unit for milliseconds
},

- You can also use kibana UI:

As a workaround for regular indices, you can use sub-aggs with .jq
curl -u username:password -s -X POST "https://localhost:9200/_all/_search?size=0" -H 'Content-Type: application/json' -d '{
"aggs": {
"indices": {
"terms": { "field": "_index", "size": 1000 },
"aggs": {
"last_updated": { "max": { "field": "@timestamp" } }
}
}
}
}' | jq -r '.aggregations.indices.buckets[] | "\(.key) \(.last_updated.value_as_string)"'