-
Notifications
You must be signed in to change notification settings - Fork 3
/
Copy pathrun_index_init.py
72 lines (51 loc) · 1.34 KB
/
run_index_init.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
63
64
65
66
67
68
import json
from elasticsearch import Elasticsearch
'''
Index Parameter
'''
INDEX_NAME = "pubmed"
TYPE_NAME = "pubmed_meta"
NUMBER_SHARDS = 1 # keep this as one if no cluster
NUMBER_REPLICAS = 0
'''
input file path
'''
index_init_config_file = './config/index_init_config.json'
'''
Start Indexing initiation =====================
'''
if __name__ == '__main__':
'''
Import index initial configuration file
'''
with open(index_init_config_file,'r') as f:
index_init_config = json.load(f)
'''
Create a index request body
'''
request_body = {
"settings": {
"number_of_shards": NUMBER_SHARDS,
"number_of_replicas": NUMBER_REPLICAS
},
"mappings": {
TYPE_NAME: {
"properties": index_init_config
}
}
}
'''
Start elasticsearch
'''
es = Elasticsearch()
'''
Delete old index if exist
'''
if es.indices.exists(INDEX_NAME):
res = es.indices.delete(index = INDEX_NAME)
print("Deleting index %s , Response: %s" % (INDEX_NAME, res))
'''
Create new index
'''
res = es.indices.create(index = INDEX_NAME, body = request_body)
print("Successfully, created index %s , Response: %s" % (INDEX_NAME, res))