feat:增加Elasticsearch功能

This commit is contained in:
2025-09-24 20:04:23 +08:00
parent 842da15886
commit ef938e6d97
5 changed files with 105 additions and 3 deletions

View File

@@ -0,0 +1,36 @@
from datetime import datetime
from config.elastic import es, BLOG_INDEX
from schemas.blog_elastic import BlogElastic
def create_blog(blog: BlogElastic) -> bool:
now = datetime.now()
blog.createTime = now
blog.updateTime = now
es.index(
index=BLOG_INDEX,
id=blog.id,
body=blog.model_dump()
)
return True
def update_blog(blog: BlogElastic) -> bool:
blog.updateTime = datetime.now()
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