all_sql_steps , repair qa_qanon
This commit is contained in:
@@ -253,7 +253,7 @@ class ElasticHelper:
|
||||
path_back,
|
||||
index_name,
|
||||
file_name="",
|
||||
body={"size": 1000},
|
||||
body={},
|
||||
byzip=True,
|
||||
fields=[],
|
||||
noFields=[],
|
||||
@@ -270,6 +270,8 @@ class ElasticHelper:
|
||||
if body == {}:
|
||||
s_res = self.es.search(index=index_name, scroll="5m", size=1000)
|
||||
else:
|
||||
if not "size" in body :
|
||||
body["size"] = 1000
|
||||
s_res = self.es.search(index=index_name, scroll="5m", body=body)
|
||||
self.total = s_res["hits"]["total"]["value"]
|
||||
if self.total == 0:
|
||||
@@ -651,7 +653,7 @@ class ElasticHelper:
|
||||
# - دادهها را به صورت bulk وارد میکند
|
||||
# - از helpers.bulk Elasticsearch استفاده میکند
|
||||
# -----------------------------end----------------------------
|
||||
def importJsonDataToElastic(self, jsonData, index_name, fields=[]):
|
||||
def importJsonDataToElastic(self, jsonData, index_name, fields=[], streem_state = False):
|
||||
chunk_size = 100000
|
||||
raise_on_error = False
|
||||
raise_on_exception = False
|
||||
@@ -677,15 +679,29 @@ class ElasticHelper:
|
||||
"_source": source,
|
||||
}
|
||||
)
|
||||
helpers.bulk(
|
||||
self.es,
|
||||
actions,
|
||||
chunk_size,
|
||||
raise_on_error,
|
||||
raise_on_exception,
|
||||
stats_only,
|
||||
yield_ok,
|
||||
)
|
||||
if streem_state :
|
||||
### /// برای مواردی که نیاز هست خطا فهمیده شود
|
||||
for ok, result in helpers.streaming_bulk(
|
||||
self.es,
|
||||
actions,
|
||||
raise_on_error=False,
|
||||
raise_on_exception=False,
|
||||
):
|
||||
if not ok:
|
||||
print("Error:", result)
|
||||
|
||||
else :
|
||||
success, errors = helpers.bulk(
|
||||
self.es,
|
||||
actions,
|
||||
chunk_size,
|
||||
raise_on_error,
|
||||
raise_on_exception,
|
||||
stats_only,
|
||||
yield_ok,
|
||||
)
|
||||
return success, errors
|
||||
|
||||
|
||||
# ----------------------------start---------------------------
|
||||
# متد fileToElastic:
|
||||
@@ -758,7 +774,7 @@ class ElasticHelper:
|
||||
print("index:", index_name, "=>", filename)
|
||||
with zObject.open(filename) as file:
|
||||
data = json.loads(file.read())
|
||||
self.importJsonDataToElastic(data, index_name, fields)
|
||||
result = self.importJsonDataToElastic(data, index_name, fields)
|
||||
|
||||
self.es.indices.refresh(index=index_name)
|
||||
print(self.es.cat.count(index=index_name, format="json"))
|
||||
|
||||
Reference in New Issue
Block a user