Merge branch 'master' of https://git2.tavasi.ir/develop/dataParsers
This commit is contained in:
@@ -83,45 +83,46 @@ def extract_json_context_id_rules_labels(
|
||||
index_name="mj_qa_rule",
|
||||
):
|
||||
input_data = DataHelper.load_orjson(json_path)
|
||||
print(
|
||||
f'input_data {len(input_data)}'
|
||||
)
|
||||
print(f"input_data {len(input_data)}")
|
||||
bulk_data = []
|
||||
total_count = 0
|
||||
failed = 0
|
||||
pass_data = 0
|
||||
|
||||
for _id1, (context_id, rule_label_data) in enumerate(input_data.items(), start=1):
|
||||
print(f"context_id {context_id}")
|
||||
# print(f"context_id {context_id}")
|
||||
for _id2, item in enumerate(rule_label_data, start=1):
|
||||
rule_id = context_id + "-" + str(_id2)
|
||||
try:
|
||||
old_data = elastic.get_document(index_name, rule_id)
|
||||
old_data = old_data["_source"]
|
||||
item_obj = OutputLabels.model_validate(item)
|
||||
new_item = convert_OutputLabels_to_es_schema(item_obj)
|
||||
old_data["label_object"] = new_item
|
||||
_old_detail = old_data.get("label_object", None)
|
||||
if not _old_detail:
|
||||
item_obj = OutputLabels.model_validate(item)
|
||||
new_item = convert_OutputLabels_to_es_schema(item_obj)
|
||||
old_data["label_object"] = new_item
|
||||
else:
|
||||
pass_data += 1
|
||||
if pass_data >= 1000:
|
||||
print(f"pass_data {pass_data}")
|
||||
pass_data = 0
|
||||
continue
|
||||
except:
|
||||
failed += 1
|
||||
continue
|
||||
|
||||
bulk_data.append(
|
||||
{"_id": old_data["id"], "_source": old_data}
|
||||
)
|
||||
# qs648706-1
|
||||
bulk_data.append({"_id": old_data["id"], "_source": old_data})
|
||||
# qs648706-1
|
||||
|
||||
if len(bulk_data) >= 100:
|
||||
total_count += len(bulk_data)
|
||||
print(
|
||||
"=" * 10, "to_elastic , total=" + str(total_count)
|
||||
)
|
||||
print("=" * 10, "to_elastic , total=" + str(total_count))
|
||||
elastic.updateBulkList(bulk_data, index_name)
|
||||
bulk_data = []
|
||||
|
||||
if len(bulk_data) >= 0:
|
||||
total_count += len(bulk_data)
|
||||
print(
|
||||
"=" * 10, "to_elastic , total=" + str(total_count)
|
||||
)
|
||||
print("=" * 10, "to_elastic , total=" + str(total_count))
|
||||
elastic.updateBulkList(bulk_data, index_name)
|
||||
bulk_data = []
|
||||
# qs648706-1
|
||||
|
||||
Reference in New Issue
Block a user