-
Notifications
You must be signed in to change notification settings - Fork 0
/
CreateMappings.py
70 lines (55 loc) · 2.22 KB
/
CreateMappings.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
69
70
import sys
import os
import elasticsearchHandler
import argparse
import json
import glob
from elasticsearchHandler import elasticSearchHandler
def createDataStructures(server, port, idx, MappingsFile, xmlFile):
global globalElasticHandler
elasticHandler = None
if globalElasticHandler != None:
elasticHandler = globalElasticHandler
else:
elasticHandler = elasticSearchHandler(server, port)
globalElasticHandler = elasticHandler
# elasticHandler = elasticSearchHandler(server,port)
settingsfile = open(MappingsFile, "r")
settings = settingsfile.read()
elasticHandler.createIndex(idx, settings)
def createDataStructure(server, port, idx, MappingsFile):
global globalElasticHandler
elasticHandler = None
if globalElasticHandler != None:
elasticHandler = globalElasticHandler
else:
elasticHandler = elasticSearchHandler(server, port)
# elasticHandler = elasticSearchHandler(server,port)
settingsfile = open(MappingsFile, "r")
settings = settingsfile.read()
elasticHandler.createIndex(idx, settings)
def dropIndex(server, port, idx):
global globalElasticHandler
elasticHandler = None
if globalElasticHandler != None:
elasticHandler = globalElasticHandler
else:
elasticHandler = elasticSearchHandler(server, port)
globalElasticHandler = elasticHandler
# print("drop")
# elasticHandler = elasticSearchHandler(server, port)
elasticHandler.dropIndex(idx)
# print("drop")
if __name__ == '__main__':
parser = argparse.ArgumentParser()
parser.add_argument('server', help='Ipaddress or logicalname for elastic server')
parser.add_argument('port', help='portnr for server')
parser.add_argument('mappingsDir', help='Directory with all mapping files')
args = parser.parse_args()
mappingsString=args.mappingsDir + "/"+ "mappings.*"
for filenow in glob.glob(mappingsString):
indexName = filenow.split(".")[1]
dropIndex(args.server, args.port, indexName)
for filenow in glob.glob(mappingsString):
indexName=filenow.split(".")[1]
createDataStructure(args.server, args.port, indexName, filenow)