nlp_tags embedding

This commit is contained in:
hsafaei
2025-02-01 09:28:50 +03:30
parent 0479c89387
commit d2b56991a0
15 changed files with 1197 additions and 659 deletions
+59 -32
View File
@@ -59,10 +59,13 @@ class ElasticHelper():
return resp
def backupIndexToZipfile(self, path_back, index_name, out_name, query={}, byzip = True) :
def backupIndexToZipfile(self, path_back, index_name, out_name= '', query={}, byzip = True) :
print('*' * 50, ' start backup -->', index_name)
self.counter = 0
out = out_name
if out_name == '' :
out = index_name
if byzip:
fout = zipfile.ZipFile(path_back + "/"+ out + '.zip', 'w')
@@ -107,6 +110,25 @@ class ElasticHelper():
scroll_size = len(s_res['hits']['hits'])
def restorFileToElastic(self, path_back, index_name, app_key = '', queryDelete = True, map_name='') :
if not os.path.exists(path_back) :
print(' **** error *** path not exist: ', path_back)
return False
file_path = path_back + '/' + index_name + '.zip'
if not os.path.exists(file_path ) :
return False
if queryDelete :
# اگر وجود داشته باشد، از کاربر برای حذفش سوال میکند
if self.deleteIndex(index_name) :
self.createIndex(index_name, app_key, map_name)
self.zipFileToElastic(file_path, index_name)
else : # اگر وجود داشته باشد پرش می کند و کاری نمیکند
self.createIndex(index_name, app_key, map_name)
self.zipFileToElastic(file_path, index_name)
def renameElasticIndex(self, index_name_i, index_name_o, app_key = '', map_name='') :
if self.createIndex(index_name_o, app_key, map_name) :
@@ -135,22 +157,6 @@ class ElasticHelper():
def restorFileToElastic(self, path_back, index_name, app_key = '', queryDelete = True) :
if not os.path.exists(path_back) :
return False
file_path = path_back + '/' + index_name + '.zip'
if not os.path.exists(file_path ) :
return False
if queryDelete :
# اگر وجود داشته باشد، از کاربر برای حذفش سوال میکند
if self.deleteIndex(index_name) :
self.createIndex(index_name, app_key)
self.zipFileToElastic(file_path, index_name)
else : # اگر وجود داشته باشد پرش می کند و کاری نمیکند
self.createIndex(index_name, app_key)
self.zipFileToElastic(file_path, index_name)
def deleteIndex(self, index_name) :
if not self.es.indices.exists(index=index_name) :
@@ -243,6 +249,41 @@ class ElasticHelper():
return False
def updateBulkList(self, listData, index_name):
chunk_size=100000
raise_on_error=False
raise_on_exception=False
stats_only=True
yield_ok = False
for item in listData:
actions = [{
"_op_type": "update",
"_index": index_name,
"_id" : item['_id'],
"doc": item['_source']
}
]
helpers.bulk(self.es, actions, chunk_size, raise_on_error, raise_on_exception, stats_only, yield_ok )
def importBulkList(self, listData, index_name):
chunk_size=100000
raise_on_error=False
raise_on_exception=False
stats_only=True
yield_ok = False
for item in listData:
actions = [{
"_op_type": "index",
"_index": index_name,
"_id" : item['_id'],
"_source": item['_source']
}
]
helpers.bulk(self.es, actions, chunk_size, raise_on_error, raise_on_exception, stats_only, yield_ok )
def importJsonDataToElastic(self, jsonData, index_name):
chunk_size=100000
raise_on_error=False
@@ -259,21 +300,7 @@ class ElasticHelper():
}
]
helpers.bulk(self.es, actions, chunk_size, raise_on_error, raise_on_exception, stats_only, yield_ok )
# actions = []
# for item in jsonData:
# actions.append(
# {
# "_op_type": "index",
# "_index": index_name,
# "_id" : item['_id'],
# "_source": item['_source']
# }
# )
# helpers.bulk(self.es, actions, chunk_size, raise_on_error, raise_on_exception, stats_only, yield_ok )
# self.es.indices.refresh(index=index_name)
# self.counter = self.es.cat.count(index=index_name, format="json")
# print('-' * 5, 'import data count : ', str(self.counter), '\n' )
def fileToElastic(self, file_path, index_name, limit_pack = -1):