-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathes_bulk_request.py
48 lines (40 loc) · 1003 Bytes
/
es_bulk_request.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
44
45
46
47
48
import asyncio
import time
from datastore.main import ElasticsearchRequestHandler
es = ElasticsearchRequestHandler()
data_for_es = [{
"product": {
"id": 10,
"name": "Funny Farm House Ketchup",
"category": "Dips and Ketchups",
"price": 100,
"stock": 5,
},
"update_ts": 1625931472
}, {
"product": {
"id": 11,
"name": "Salsa Dip",
"category": "Dips and Ketchups",
"price": 20,
"stock": 100
},
"update_ts": 1625931472
}, {
"product": {
"id": 12,
"name": "Cheese Nachos",
"category": "Snacks",
"price": 13.75,
"stock": 1
},
"update_ts": 1625931472
}]
async def main():
s = time.perf_counter()
await es.bulk_indexing(data_for_es=data_for_es)
elapsed = time.perf_counter() - s
print(f"{__file__} executed in {elapsed:0.2f} seconds.")
await es.close_connection()
loop = asyncio.get_event_loop()
loop.run_until_complete(main())