-
Notifications
You must be signed in to change notification settings - Fork 1
/
datastream-find-minmax.py
44 lines (37 loc) · 1.28 KB
/
datastream-find-minmax.py
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
from elasticsearch import Elasticsearch
# Connect to Elasticsearch
# Create the client instance
es = Elasticsearch(
cloud_id="ess-cloud-id",
basic_auth=("username", "password")
)
# Get the list of all backing indices for 'my-datastream'
response = es.cat.indices(index="my-datastream*", h="index", format="json")
indices = [index_info['index'] for index_info in response]
# For each backing index, find the min and max event_timestamp
results = {}
for index in indices:
response = es.search(index=index, body={
"size": 0,
"aggs": {
"min_event_timestamp": {
"min": {
"field": "event_timestamp"
}
},
"max_event_timestamp": {
"max": {
"field": "event_timestamp"
}
}
}
})
results[index] = {
"min_event_timestamp": response['aggregations']['min_event_timestamp']['value_as_string'],
"max_event_timestamp": response['aggregations']['max_event_timestamp']['value_as_string']
}
# Print results
for index, values in results.items():
print(f"Index: {index}")
print(f"\tMin event_timestamp: {values['min_event_timestamp']}")
print(f"\tMax event_timestamp: {values['max_event_timestamp']}")