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

13
config/elastic.py Normal file
View File

@@ -0,0 +1,13 @@
from elasticsearch import Elasticsearch
from schemas.blog_elastic import BLOG_MAPPING
from config.logging import logger
ES_HOSTS = ["http://localhost:9200"]
BLOG_INDEX = "blog"
es = Elasticsearch(hosts=ES_HOSTS)
if not es.indices.exists(index=BLOG_INDEX):
es.indices.create(index=BLOG_INDEX, body=BLOG_MAPPING)
logger.info(f"Elastic索引 {BLOG_INDEX} 创建成功")