list_tags qanon_usefull
This commit is contained in:
+42
-26
@@ -10,8 +10,13 @@ class ElasticHelper():
|
||||
counter = 0
|
||||
total = 0
|
||||
id = ""
|
||||
path_mappings = os.getcwd() + '/repo/_other/'
|
||||
|
||||
def __init__(self, es_url="http://127.0.0.1:6900", es_pass="", es_user="elastic"):
|
||||
def __init__(self, es_url="http://127.0.0.1:6900", es_pass="", es_user="elastic", path_mappings = ""):
|
||||
|
||||
if path_mappings :
|
||||
self.path_mappings = path_mappings
|
||||
|
||||
if es_pass == '' :
|
||||
self.es = Elasticsearch(es_url)
|
||||
else:
|
||||
@@ -103,14 +108,30 @@ class ElasticHelper():
|
||||
|
||||
|
||||
def renameElasticIndex(self, index_name_i, index_name_o, app_key = '', map_name='') :
|
||||
|
||||
if self.createIndex(index_name_o, app_key, map_name) :
|
||||
self.es.reindex(
|
||||
body={
|
||||
"source": {"index": index_name_i},
|
||||
"dest": {"index": index_name_o}
|
||||
},
|
||||
wait_for_completion=True)
|
||||
|
||||
res = self.es.reindex(
|
||||
body={
|
||||
"source": {"index": index_name_i},
|
||||
"dest": {"index": index_name_o}
|
||||
},
|
||||
wait_for_completion=False)
|
||||
|
||||
print(type(res))
|
||||
print(res)
|
||||
|
||||
taskid = res["task"] if res["task"] else ""
|
||||
#tasks = client.TasksClient(self.es)
|
||||
tasks = self.es.tasks
|
||||
while True :
|
||||
res = tasks.get(task_id = taskid)
|
||||
if res["completed"] :
|
||||
break
|
||||
|
||||
# print( res["task"])
|
||||
print( '----', index_name_o, ' imported : ', res["task"]["status"]["total"] , ' / ', res["task"]["status"]["created"])
|
||||
sleep(1)
|
||||
print( '----', index_name_o, ' complated')
|
||||
|
||||
|
||||
|
||||
@@ -176,9 +197,9 @@ class ElasticHelper():
|
||||
print("....... index exist ! ... not created")
|
||||
|
||||
|
||||
def createIndex(self, index_name, app_key='', sub_path='general/', map_name=''):
|
||||
def createIndex(self, index_name, app_key='', map_name=''):
|
||||
|
||||
path_base = os.getcwd() + '/repo/_other/'
|
||||
path_base = self.path_mappings
|
||||
path_mapping1 = path_base + 'general/'
|
||||
if app_key == '' :
|
||||
app_key = 'tavasi'
|
||||
@@ -192,36 +213,31 @@ class ElasticHelper():
|
||||
print("============== exist index :", index_name )
|
||||
return True
|
||||
|
||||
path_mapping = path_base + sub_path
|
||||
mapping_file_path = path_mapping + map_name + '.json'
|
||||
if map_name == 'mj_rg_section' or map_name == 'semantic_search' :
|
||||
map_name = 'mj_qa_section'
|
||||
elif map_name[-3]=='_ai':
|
||||
map_name=[0-len(map_name)-3]
|
||||
print(map_name)
|
||||
|
||||
mapping_file_path = path_mapping1 + map_name + '.json'
|
||||
print("mapping_file_path : " , mapping_file_path)
|
||||
if not os.path.isfile(mapping_file_path):
|
||||
# if map_name[-3]=='_ai':
|
||||
# map_name=[0-len(map_name)-3]
|
||||
# print(map_name)
|
||||
# el
|
||||
if map_name == 'mj_rg_section' or map_name == 'semantic_search' :
|
||||
map_name = 'mj_qa_section'
|
||||
mapping_file_path = path_mapping + map_name + '.json'
|
||||
|
||||
if not os.path.isfile(mapping_file_path):
|
||||
mapping_file_path = path_mapping1 + map_name + '.json'
|
||||
if not os.path.isfile(mapping_file_path):
|
||||
mapping_file_path = path_mapping2 + map_name + '.json'
|
||||
|
||||
print("mapping_file_path : " , mapping_file_path)
|
||||
|
||||
|
||||
# Create Index With Mapping
|
||||
if os.path.isfile(mapping_file_path):
|
||||
mapping_file =open(mapping_file_path,'r')
|
||||
mapping_file = open( mapping_file_path,'r', encoding='utf-8' )
|
||||
mapping_file_read = mapping_file.read()
|
||||
mapping_data = json.loads(mapping_file_read)
|
||||
mapping_file.close()
|
||||
if self.es.indices.exists(index=index_name) :
|
||||
print("============== exist index :", index_name )
|
||||
return True
|
||||
self.es.indices.create(index = index_name , body = mapping_data)
|
||||
else :
|
||||
self.es.indices.create(index = index_name , body = mapping_data)
|
||||
return True
|
||||
else:
|
||||
print('*** error not find maping file elastic : *******', mapping_file_path)
|
||||
return False
|
||||
|
||||
Reference in New Issue
Block a user