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