lvl2
This commit is contained in:
@@ -1,9 +1,38 @@
|
||||
from elastic_helper import ElasticHelper
|
||||
# --------------------------- modularity
|
||||
from app.common.elastic_helper import ElasticHelper
|
||||
from pydantic import BaseModel
|
||||
|
||||
# --------------------------- global-params
|
||||
base_index_name = 'monir_test_term'
|
||||
id_data = None
|
||||
_data = None
|
||||
|
||||
|
||||
# --------------------------- function
|
||||
def generate_pydantic_model_from_mapping(model_name: str, mapping_es: dict) -> type[BaseModel]:
|
||||
fields = {}
|
||||
for field_name, field_def in mapping["properties"].items():
|
||||
es_type = field_def["type"]
|
||||
py_type = ES_TO_PYDANTIC.get(es_type, str)
|
||||
|
||||
# اضافه کردن optional بودن؟ یا default؟ بسته به نیاز
|
||||
fields[field_name] = (py_type, ...)
|
||||
|
||||
return type(name, (BaseModel,), {"__annotations__": fields})
|
||||
|
||||
|
||||
# --------------------------- flow
|
||||
es_helper = ElasticHelper(
|
||||
es_url="http://127.0.0.1:6900",
|
||||
es_user="elastic",
|
||||
# es_pass="",
|
||||
# path_mappings = ""
|
||||
)
|
||||
|
||||
|
||||
|
||||
es_helper.update_index_doc(
|
||||
is_update_state=False,
|
||||
index_name_o=base_index_name,
|
||||
eid=id_data,
|
||||
data=_data
|
||||
)
|
||||
Reference in New Issue
Block a user