-
Notifications
You must be signed in to change notification settings - Fork 0
/
setup_es_index.py
47 lines (43 loc) · 1.02 KB
/
setup_es_index.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
import requests
import json
import elasticsearch
INDEX_NAME = 'chat'
INDEX_TEMPLATE = {
'mappings': {
'_source': {
'includes': [
'id',
'room_id',
'content', # TODO remove this
]
},
'properties': {
'id': {
'type': 'long'
},
'room_id': {
'type': 'long'
},
'user_name': {
'type': 'text'
},
'content': {
'type': 'text',
'fields': {
'lang_analyzed': {
'type': 'text',
'analyzer': 'english'
}
}
}
}
}
}
def main():
es = elasticsearch.Elasticsearch()
indexes = elasticsearch.client.IndicesClient(es)
if indexes.exists(INDEX_NAME):
return
print('Creating index')
indexes.create(index=INDEX_NAME, body=INDEX_TEMPLATE)
main()