Files
blog-service/service/blog_elastic_service.py
2025-09-25 00:08:28 +08:00

38 lines
773 B
Python

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