-
-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathelastic_write.py
More file actions
26 lines (22 loc) · 899 Bytes
/
elastic_write.py
File metadata and controls
26 lines (22 loc) · 899 Bytes
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
from datetime import datetime
import random
from elasticsearch import Elasticsearch
import time
import random
hosts = ['localhost']
es = Elasticsearch(hosts)
while True:
doc = {
'timestamp': datetime.utcnow(), # Watch out for timezones. I spent two hours looking for my data, but it was in the future....
'load': random.random() * 8,
'rnd': random.randrange(100),
'name': random.choice(['Mercury', 'Venus', 'Earth', 'Mars', 'Jupiter', 'Saturn', 'Uranus', 'Neptunus']),
'yes': random.choice([True, False]),
}
index_name = 'experimental'
print(index_name)
print(doc)
res = es.index(index = index_name, doc_type = 'samples', body = doc)
print(res)
time.sleep(random.random())
# curl -X PUT -H "Content-Type: application/json" -d '{ "index": { "number_of_replicas": 0 } }' http://localhost:9200/_settings