Skip to content

Commit 5c038e6

Browse files
committed
feat: Elasticsearch access via API Key
fixed local configuration feat: Elasticsearch access via API Key: reverse testconfig
1 parent ce71d87 commit 5c038e6

File tree

8 files changed

+38
-13
lines changed

8 files changed

+38
-13
lines changed

common/doc_store/es_conn_pool.py

Lines changed: 17 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -25,7 +25,6 @@
2525

2626
@singleton
2727
class ElasticSearchConnectionPool:
28-
2928
def __init__(self):
3029
if hasattr(settings, "ES"):
3130
self.ES_CONFIG = settings.ES
@@ -52,12 +51,23 @@ def __init__(self):
5251
raise Exception(msg)
5352

5453
def _connect(self):
55-
self.es_conn = Elasticsearch(
56-
self.ES_CONFIG["hosts"].split(","),
57-
basic_auth=(self.ES_CONFIG["username"], self.ES_CONFIG[
58-
"password"]) if "username" in self.ES_CONFIG and "password" in self.ES_CONFIG else None,
59-
verify_certs= self.ES_CONFIG.get("verify_certs", False),
60-
timeout=600 )
54+
if "api_key" in self.ES_CONFIG and self.ES_CONFIG["api_key"]:
55+
logging.info('Elasticsearch connection using API_KEY')
56+
self.es_conn = Elasticsearch(
57+
self.ES_CONFIG["hosts"].split(","),
58+
api_key=self.ES_CONFIG["api_key"],
59+
verify_certs=self.ES_CONFIG.get("verify_certs", False),
60+
timeout=600
61+
)
62+
else:
63+
logging.info('Elasticsearch connection using username/password')
64+
self.es_conn = Elasticsearch(
65+
self.ES_CONFIG["hosts"].split(","),
66+
basic_auth=(self.ES_CONFIG["username"], self.ES_CONFIG["password"]) if "username" in self.ES_CONFIG and "password" in self.ES_CONFIG else None,
67+
verify_certs=self.ES_CONFIG.get("verify_certs", False),
68+
timeout=600,
69+
)
70+
6171
if self.es_conn:
6272
self.info = self.es_conn.info()
6373
return True

conf/service_conf.yaml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,7 @@ es:
2323
hosts: 'http://localhost:1200'
2424
username: 'elastic'
2525
password: 'infini_rag_flow'
26+
api_key: ''
2627
os:
2728
hosts: 'http://localhost:1201'
2829
username: 'admin'

docker/.env

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -31,7 +31,7 @@ COMPOSE_PROFILES=${DOC_ENGINE},${DEVICE}
3131
STACK_VERSION=8.11.3
3232

3333
# The hostname where the Elasticsearch service is exposed
34-
ES_HOST=es01
34+
ES_HOST=http://es01:9200
3535

3636
# The port used to expose the Elasticsearch service to the host machine,
3737
# allowing EXTERNAL access to the service running inside the Docker container.
@@ -154,7 +154,7 @@ ADMIN_SVR_HTTP_PORT=9381
154154
SVR_MCP_PORT=9382
155155

156156
# The RAGFlow Docker image to download. v0.22+ doesn't include embedding models.
157-
RAGFLOW_IMAGE=infiniflow/ragflow:v0.24.0
157+
RAGFLOW_IMAGE=ragflow:v0.24.0
158158

159159
# If you cannot download the RAGFlow Docker image:
160160
# RAGFLOW_IMAGE=swr.cn-north-4.myhuaweicloud.com/infiniflow/ragflow:v0.24.0

docker/service_conf.yaml.template

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -20,9 +20,10 @@ minio:
2020
bucket: '${MINIO_BUCKET:-}'
2121
prefix_path: '${MINIO_PREFIX_PATH:-}'
2222
es:
23-
hosts: 'http://${ES_HOST:-es01}:9200'
23+
hosts: '${ES_HOST:-http://es01:9200}'
2424
username: '${ES_USER:-elastic}'
2525
password: '${ELASTIC_PASSWORD:-infini_rag_flow}'
26+
api_key: '${ELASTIC_API_KEY:-}'
2627
os:
2728
hosts: 'http://${OS_HOST:-opensearch01}:9201'
2829
username: '${OS_USER:-admin}'

helm/templates/elasticsearch-config.yaml

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{{- if eq .Values.env.DOC_ENGINE "elasticsearch" -}}
2+
{{- if .Values.elasticsearch.enabled }}
23
apiVersion: v1
34
kind: ConfigMap
45
metadata:
@@ -14,4 +15,5 @@ data:
1415
cluster.routing.allocation.disk.watermark.high: 3gb
1516
cluster.routing.allocation.disk.watermark.flood_stage: 2gb
1617
TZ: {{ .Values.env.TZ }}
18+
{{- end }}
1719
{{- end -}}

helm/templates/elasticsearch.yaml

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
{{- if eq .Values.env.DOC_ENGINE "elasticsearch" -}}
2+
{{- if .Values.elasticsearch.enabled }}
23
apiVersion: v1
34
kind: PersistentVolumeClaim
45
metadata:
@@ -128,4 +129,5 @@ spec:
128129
port: 9200
129130
targetPort: http
130131
type: {{ .Values.elasticsearch.service.type }}
131-
{{- end -}}
132+
{{- end }}
133+
{{- end -}}

helm/templates/env.yaml

Lines changed: 7 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -57,8 +57,13 @@ stringData:
5757
Only provide env vars for enabled doc engine
5858
*/}}
5959
{{- if eq .Values.env.DOC_ENGINE "elasticsearch" }}
60-
ES_HOST: {{ printf "%s-es.%s.svc" (include "ragflow.fullname" .) .Release.Namespace }}
61-
ELASTIC_PASSWORD: {{ .Values.env.ELASTIC_PASSWORD | required "ELASTIC_PASSWORD is required" }}
60+
{{- if .Values.elasticsearch.enabled }}
61+
ES_HOST: {{ printf "http://%s-es.%s.svc" (include "ragflow.fullname" .) .Release.Namespace }}
62+
ELASTIC_PASSWORD: {{ .Values.env.ELASTIC_PASSWORD }}
63+
{{- else }}
64+
ES_HOST: {{ .Values.env.ES_HOST }}
65+
ELASTIC_API_KEY: {{ .Values.env.ELASTIC_API_KEY }}
66+
{{- end }}
6267
{{- else if eq .Values.env.DOC_ENGINE "infinity" }}
6368
INFINITY_HOST: {{ printf "%s-infinity.%s.svc" (include "ragflow.fullname" .) .Release.Namespace }}
6469
{{- else if eq .Values.env.DOC_ENGINE "opensearch" }}

helm/values.yaml

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -25,6 +25,9 @@ env:
2525

2626
# The password for Elasticsearch
2727
ELASTIC_PASSWORD: infini_rag_flow_helm
28+
# if using elastic-cloud deployment, set enabled: false
29+
# ES_HOST: 'https://xxxx'
30+
# ELASTIC_API_KEY: replace-if-used-elastic-cloud
2831

2932
# The password for OpenSearch.
3033
# At least one uppercase letter, one lowercase letter, one digit, and one special character
@@ -130,6 +133,7 @@ infinity:
130133
type: ClusterIP
131134

132135
elasticsearch:
136+
enabled: true
133137
image:
134138
repository: elasticsearch
135139
tag: "8.11.3"

0 commit comments

Comments
 (0)