This commit is contained in:
parent
8db9449b36
commit
8087eabd5e
36
app.py
36
app.py
|
|
@ -106,21 +106,35 @@ def extract_index_structure(es_client, index_name):
|
|||
existing_fields[full_key] = "dict"
|
||||
parse_document(value, full_key, existing_fields)
|
||||
elif isinstance(value, list):
|
||||
if len(value) > 0 and isinstance(value[0], dict):
|
||||
existing_fields[full_key] = "list[dict]"
|
||||
parse_document(value[0], full_key, existing_fields)
|
||||
elif len(value) > 0:
|
||||
existing_fields[full_key] = f"list[{type(value[0]).__name__}]"
|
||||
else:
|
||||
# 遍历列表中的所有元素,确保全面检查类型
|
||||
list_types = set()
|
||||
for item in value:
|
||||
list_types.add(type(item).__name__)
|
||||
if isinstance(item, dict):
|
||||
parse_document(item, full_key, existing_fields)
|
||||
|
||||
if len(list_types) == 0:
|
||||
existing_fields[full_key] = "list[empty]"
|
||||
elif len(list_types) == 1:
|
||||
existing_fields[full_key] = f"list[{list_types.pop()}]"
|
||||
else:
|
||||
existing_fields[full_key] = "list[mixed]"
|
||||
else:
|
||||
existing_fields[full_key] = type(value).__name__
|
||||
elif isinstance(doc, list):
|
||||
if len(doc) > 0:
|
||||
if isinstance(doc[0], dict):
|
||||
parse_document(doc[0], parent_key, existing_fields)
|
||||
else:
|
||||
existing_fields[f"{parent_key}[]"] = type(doc[0]).__name__
|
||||
# 如果是根级别的列表,遍历元素并记录类型
|
||||
list_types = set()
|
||||
for item in doc:
|
||||
list_types.add(type(item).__name__)
|
||||
if isinstance(item, dict):
|
||||
parse_document(item, parent_key, existing_fields)
|
||||
|
||||
if len(list_types) == 0:
|
||||
existing_fields[parent_key] = "list[empty]"
|
||||
elif len(list_types) == 1:
|
||||
existing_fields[parent_key] = f"list[{list_types.pop()}]"
|
||||
else:
|
||||
existing_fields[parent_key] = "list[mixed]"
|
||||
else:
|
||||
existing_fields[parent_key] = type(doc).__name__
|
||||
|
||||
|
|
|
|||
Loading…
Reference in New Issue