first commit
This commit is contained in:
@@ -0,0 +1,67 @@
|
||||
from app.common.elastic_helper import ElasticHelper
|
||||
import os
|
||||
import orjson
|
||||
from pathlib import Path
|
||||
from dotenv import load_dotenv
|
||||
from elasticsearch.helpers import scan
|
||||
|
||||
def load_orjson(path: str | Path):
|
||||
path = Path(path)
|
||||
with path.open("rb") as f: # باید باینری باز بشه برای orjson
|
||||
return orjson.loads(f.read())
|
||||
|
||||
|
||||
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")
|
||||
_index = os.getenv("INDEX_NAME")
|
||||
|
||||
es_helper = ElasticHelper(
|
||||
es_pass=password,
|
||||
es_url=url,
|
||||
es_user=user_name,
|
||||
)
|
||||
|
||||
es = es_helper.es
|
||||
|
||||
fields =[
|
||||
"_id",
|
||||
"qanon_id",
|
||||
"content",
|
||||
"qanon_title",
|
||||
"state_etebar",
|
||||
"qanon_etebar",
|
||||
"other_info.full_path"
|
||||
|
||||
]
|
||||
|
||||
result = list(
|
||||
scan(
|
||||
es,
|
||||
index=_index,
|
||||
query={
|
||||
"_source": fields,
|
||||
"query":
|
||||
{"match_all": {}},
|
||||
},
|
||||
)
|
||||
)
|
||||
|
||||
# result= es_helper.es_iterate_all_documents(
|
||||
# index=_index,
|
||||
# _source=filed, query={"match_all": {}} # , size=3
|
||||
# )
|
||||
print(f'result {len(result)}')
|
||||
save_orjson(
|
||||
data=result,
|
||||
path='./qs_data_for_h100_1.json'
|
||||
)
|
||||
|
||||
# python -m app.import_json_from_es.main
|
||||
Reference in New Issue
Block a user