feat:增加Elasticsearch功能
This commit is contained in:
13
config/elastic.py
Normal file
13
config/elastic.py
Normal 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} 创建成功")
|
||||
Reference in New Issue
Block a user