-
Notifications
You must be signed in to change notification settings - Fork 0
/
es_setup.py
62 lines (53 loc) · 1.5 KB
/
es_setup.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
49
50
51
52
53
54
55
56
57
58
59
60
61
62
import asyncio
import aiohttp
import time
from datastore.main import ElasticsearchRequestHandler
es = ElasticsearchRequestHandler()
request_body = {
"settings": {
"number_of_shards": 1,
"number_of_replicas": 1
},
'mappings': {
'properties': {
'product': {
'type': 'object',
'properties': {
'name': {
'index': True,
'type': 'text'
},
'category': {
'index': True,
'type': 'text'
},
'id': {
'index': True,
'type': 'integer'
},
'price': {
'index': True,
'type': 'float'
},
'stock': {
'index': True,
'type': 'integer'
}
}
},
'update_ts': {
'index': True,
'type': 'date',
'format': 'epoch_second'
}
}
}
}
async def main():
s = time.perf_counter()
await es.setup(mappings_and_settings=request_body)
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())