from datetime import datetime from config.elastic import es, BLOG_INDEX from schemas.blog_elastic import BlogElastic def add_blog_elastic(blog: BlogElastic) -> bool: now = datetime.now() blog.createTime = now.strftime("%Y-%m-%d %H:%M:%S") blog.updateTime = now.strftime("%Y-%m-%d %H:%M:%S") es.index( index=BLOG_INDEX, id=blog.id, body=blog.model_dump() ) return True def update_blog_elastic(blog: BlogElastic) -> bool: now = datetime.now() blog.updateTime = now.strftime("%Y-%m-%d %H:%M:%S") es.index( index=BLOG_INDEX, id=blog.id, body=blog.model_dump() ) return True def delete_blog(blog_id: int) -> bool: es.delete(index=BLOG_INDEX, id=blog_id) return True