bug plan
This commit is contained in:
+24
-16
@@ -37,6 +37,8 @@ def recersive_sections(
|
|||||||
|
|
||||||
# Append current section
|
# Append current section
|
||||||
list_bulk.append({
|
list_bulk.append({
|
||||||
|
"_id": node_id,
|
||||||
|
"_source":{
|
||||||
"id": node_id,
|
"id": node_id,
|
||||||
"title": title,
|
"title": title,
|
||||||
"version_key": "D49_oss120",
|
"version_key": "D49_oss120",
|
||||||
@@ -45,6 +47,7 @@ def recersive_sections(
|
|||||||
"child_order": child_order,
|
"child_order": child_order,
|
||||||
"tcode": tcode_label,
|
"tcode": tcode_label,
|
||||||
"time_create": time.time()
|
"time_create": time.time()
|
||||||
|
}
|
||||||
})
|
})
|
||||||
|
|
||||||
# Process subsections (children)
|
# Process subsections (children)
|
||||||
@@ -73,9 +76,10 @@ def import_paln_json_to_elastic(elastic, file_path, index_name):
|
|||||||
|
|
||||||
total = len(data)
|
total = len(data)
|
||||||
list_bulk = []
|
list_bulk = []
|
||||||
batch_size = 200
|
batch_size = 20
|
||||||
processed_count = 0
|
processed_count = 0
|
||||||
total_update = 0
|
total_update = 0
|
||||||
|
batch_size_number = 1
|
||||||
|
|
||||||
tcode_label = data.get("law_title")
|
tcode_label = data.get("law_title")
|
||||||
if not tcode_label :
|
if not tcode_label :
|
||||||
@@ -85,37 +89,41 @@ def import_paln_json_to_elastic(elastic, file_path, index_name):
|
|||||||
# Step 1: Add root node (the law itself)
|
# Step 1: Add root node (the law itself)
|
||||||
root_id = uuid.uuid4().hex[:8]
|
root_id = uuid.uuid4().hex[:8]
|
||||||
root_path = data.get("law_title") + "/"
|
root_path = data.get("law_title") + "/"
|
||||||
list_bulk.append({
|
# list_bulk.append({
|
||||||
"id": root_id,
|
# "_id": root_id,
|
||||||
"title": data.get("law_title"),
|
# "_source": {
|
||||||
"version_key": "D49_oss120",
|
# "id": root_id,
|
||||||
"full_path": root_path,
|
# "title": data.get("law_title"),
|
||||||
"parent_id": 0, # or 0 if you prefer integer root parent
|
# "version_key": "D49_oss120",
|
||||||
"child_order": 0,
|
# "full_path": root_path,
|
||||||
"tcode": tcode_label,
|
# "parent_id": 0, # or 0 if you prefer integer root parent
|
||||||
"time_create": time.time()
|
# "child_order": 0,
|
||||||
})
|
# "tcode": tcode_label,
|
||||||
|
# "time_create": time.time()
|
||||||
|
# }
|
||||||
|
# })
|
||||||
|
|
||||||
# Step 2: Recursively process top-level sections
|
# Step 2: Recursively process top-level sections
|
||||||
for idx, section in enumerate(data.get("sections", []), start=1):
|
for idx, section in enumerate(data.get("sections", []), start=1):
|
||||||
|
print("..start..", idx, section["title"])
|
||||||
recersive_sections(
|
recersive_sections(
|
||||||
section=section,
|
section=section,
|
||||||
list_bulk=list_bulk,
|
list_bulk=list_bulk,
|
||||||
parent_id=root_id,
|
parent_id=0,
|
||||||
parent_path=root_path,
|
parent_path=root_path,
|
||||||
child_order=idx,
|
child_order=idx,
|
||||||
tcode_label=tcode_label
|
tcode_label=tcode_label
|
||||||
)
|
)
|
||||||
|
|
||||||
if len(list_bulk) >= batch_size :
|
if len(list_bulk) >= batch_size :
|
||||||
elastic.updateBulkList(list_bulk, index_name)
|
elastic.importBulkList(list_bulk, index_name)
|
||||||
total_update += len(list_bulk)
|
total_update += len(list_bulk)
|
||||||
list_bulk = []
|
list_bulk = []
|
||||||
print("updated batch : ", batch_size_number, f" {total_update}/{total} --->", file_path)
|
print("updated batch : ", batch_size_number, f" {total_update}/{total} --->", file_path)
|
||||||
batch_size_number += 1
|
batch_size_number += 1
|
||||||
|
|
||||||
if list_bulk:
|
if list_bulk:
|
||||||
elastic.updateBulkList(list_bulk, index_name)
|
elastic.importBulkList(list_bulk, index_name)
|
||||||
total_update += len(list_bulk)
|
total_update += len(list_bulk)
|
||||||
print(" .... finish updated batch : ", batch_size_number, f" {total_update}/{total} --->", file_path)
|
print(" .... finish updated batch : ", batch_size_number, f" {total_update}/{total} --->", file_path)
|
||||||
batch_size_number += 1
|
batch_size_number += 1
|
||||||
@@ -147,8 +155,8 @@ if __name__ == "__main__":
|
|||||||
path_base_map = "G:/Project2/gateway2_main/repo/_other/"
|
path_base_map = "G:/Project2/gateway2_main/repo/_other/"
|
||||||
elastic = ElasticHelper(host, password, "elastic", path_base_map)
|
elastic = ElasticHelper(host, password, "elastic", path_base_map)
|
||||||
|
|
||||||
file_path=r'D:\init_mahdi\project\dataParsers\data\plan_آمار_برنامه_و_بودجه.json'
|
file_path=r'data/plans/gpt120b_49_1/data_1/آمار، برنامه و بودجه.json'
|
||||||
index_name='mj'
|
index_name='mj_plan'
|
||||||
import_paln_json_to_elastic(
|
import_paln_json_to_elastic(
|
||||||
elastic=elastic,
|
elastic=elastic,
|
||||||
file_path=file_path,
|
file_path=file_path,
|
||||||
|
|||||||
Reference in New Issue
Block a user