From 766624c04cea484117bbfc911cb61512228e364d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?=E6=9D=8E=E5=A6=82=E5=A8=81?= Date: Mon, 15 Dec 2025 18:04:58 +0800 Subject: [PATCH] feat: es --- docker/ES_Dockerfile | 4 ++++ src/pipeline/core/es_client.py | 6 ++++-- 2 files changed, 8 insertions(+), 2 deletions(-) create mode 100644 docker/ES_Dockerfile diff --git a/docker/ES_Dockerfile b/docker/ES_Dockerfile new file mode 100644 index 0000000..df9d377 --- /dev/null +++ b/docker/ES_Dockerfile @@ -0,0 +1,4 @@ +FROM docker.elastic.co/elasticsearch/elasticsearch:9.2.2 + +# 安装 IK 分词器, 最大兼容中文 +RUN bin/elasticsearch-plugin install https://get.infini.cloud/elasticsearch/analysis-ik/8.4.1 diff --git a/src/pipeline/core/es_client.py b/src/pipeline/core/es_client.py index 1718597..1f01dde 100644 --- a/src/pipeline/core/es_client.py +++ b/src/pipeline/core/es_client.py @@ -1,10 +1,11 @@ import httpx from pipeline.config import config + class AsyncES: def __init__(self): self.base = f"{config['es_host']}:{config['es_port']}" - self.auth = (config["es_user"], config['es_password']) + self.auth = (config["es_user"], config["es_password"]) async def create_index(self, index: str): """ @@ -15,7 +16,7 @@ class AsyncES: f"{self.base}/{index}", auth=self.auth, json={ - "settings": {"analysis": {"analyzer": {"default": {"type": "standard"}}}}, + "settings": {"analysis": {"analyzer": {"default": {"type": "ik_max_word"}}}}, "mappings": { "properties": { "text": {"type": "text"}, @@ -42,4 +43,5 @@ class AsyncES: resp = await client.post(f"{self.base}/{index}/_search", auth=self.auth, json={"size": top_k, "query": {"match": {"text": query}}}) return resp.json() + es_client = AsyncES