59 lines
1.9 KiB
Python
59 lines
1.9 KiB
Python
from app.common.elastic_helper import ElasticHelper
|
|
from app.common.data_helper import DataHelper
|
|
import os
|
|
import time, traceback, uuid, orjson
|
|
from elasticsearch.helpers import scan
|
|
from dotenv import load_dotenv
|
|
def save_orjson(path, data):
|
|
with open(path, "wb") as f:
|
|
f.write(
|
|
orjson.dumps(data, option=orjson.OPT_INDENT_2 | orjson.OPT_NON_STR_KEYS)
|
|
)
|
|
|
|
load_dotenv()
|
|
url = os.getenv("ES_URL")
|
|
user_name = os.getenv("ES_USER_NAME")
|
|
password = os.getenv("ES_PASSWORD")
|
|
|
|
|
|
term_index_name = "mn_term"
|
|
meet_index_name = "mn_meet"
|
|
ment_index_name = "mn_meet_entity"
|
|
dash = "-" * 25
|
|
es_helper = ElasticHelper(
|
|
es_url=url,
|
|
es_user="elastic",
|
|
es_pass=password,
|
|
# path_mappings = ""
|
|
)
|
|
fields = [ "content", "subtitle", "title", "sanad_id", "id", "main_type", "sub_type"]
|
|
|
|
es_helper
|
|
|
|
print(f"fields {fields}")
|
|
# fields ['id', 'sort_date_timestamp', 'title', 'subtitle', 'research_code', 'content', 'version_info', 'meet_lid', 'meet_id', 'meet_no', 'meet_code', 'allwords', 'keywords', 'person_code', 'subject', 'city', 'author', 'begin_year', 'begin_date', 'end_date', 'branch', 'ralation', 'research_id', 'mintro', 'mindex', 'RowNum', 'resource_info', 'in_tadvin', 'format', 'verb', 'address', 'attendees', 'amplify', 'audience', 'place', 'permit_tags', 'photos', 'tags', 'films', 'sounds', 'file_links', 'sound_links', 'video_links', 'photo_links']
|
|
|
|
es = es_helper.es
|
|
# old_data = es_helper.search(
|
|
# index=old_index_name, _source=fields, query={"match_all": {}}, size=3
|
|
# )
|
|
# old_data = old_data["hits"]["hits"] # don't use in scan
|
|
################### for all data
|
|
old_data = list(
|
|
scan(
|
|
es,
|
|
index="mn_meet",
|
|
query={
|
|
"_source": fields,
|
|
"query":
|
|
# {"ids": {"values": ["pm146821"]}},
|
|
{"match_all": {}},
|
|
},
|
|
)
|
|
)
|
|
print(f'old_data {len(old_data)}')
|
|
save_orjson(
|
|
data=old_data,
|
|
path=r"./mn_meet_for_section.json"
|
|
)
|
|
# python -m dataParsers.app.monir.test |