Files
blog-service/config/elastic.py
2025-10-09 22:58:49 +08:00

17 lines
528 B
Python

from elasticsearch import Elasticsearch
from schemas.blog_elastic import BLOG_MAPPING
from config.logging import logger
ES_HOSTS = "http://host.docker.internal:9200"
ES_USER = "elastic"
ES_PASSWORD = "19940822Cxx"
BLOG_INDEX = "blog"
# 注意Python的elasticsearch的版本要和服务器的一致
es = Elasticsearch(ES_HOSTS, http_auth=(ES_USER, ES_PASSWORD))
if not es.indices.exists(index=BLOG_INDEX):
es.indices.create(index=BLOG_INDEX, body=BLOG_MAPPING)
logger.info(f"Elastic索引 {BLOG_INDEX} 创建成功")