def convert_es_hit_to_node(
    hit: Dict[str, Any], text_field: str = "content"
) -> BaseNode:
    """
    Convert an Elasticsearch search hit to a BaseNode.

    Args:
        hit: The Elasticsearch search hit
        text_field: The field name that contains the text content

    Returns:
        BaseNode: The converted node

    """
    source = hit.get("_source", {})
    metadata = source.get("metadata", {})
    text = source.get(text_field, None)
    node_id = hit.get("_id")

    try:
        node = metadata_dict_to_node(metadata)
        node.text = text
    except Exception:
        # Legacy support for old metadata format
        logger.warning(f"Could not parse metadata from hit {source.get('metadata')}")
        node_info = source.get("node_info")
        relationships = source.get("relationships", {})
        start_char_idx = None
        end_char_idx = None
        if isinstance(node_info, dict):
            start_char_idx = node_info.get("start", None)
            end_char_idx = node_info.get("end", None)

        node = TextNode(
            text=text,
            metadata=metadata,
            id_=node_id,
            start_char_idx=start_char_idx,
            end_char_idx=end_char_idx,
            relationships=relationships,
        )

    return node

    Convert an Elasticsearch search hit to a BaseNode.

    Args:
        hit: The Elasticsearch search hit
        text_field: The field name that contains the text content

    Returns:
        BaseNode: The converted node

    
llama-index-integrations/vector_stores/llama-index-vector-stores-elasticsearch/llama_index/vector_stores/elasticsearch/utils.py