1818 from requests.auth import HTTPBasicAuth
1919
2020 # Configuration
21- OPENSEARCH_HOST = os.getenv('OPENSEARCH_HOST', 'opensearch')
22- OPENSEARCH_PORT = int(os.getenv('OPENSEARCH_PORT', '9200'))
21+ OPENSEARCH_HOSTS = os.getenv('OPENSEARCH_HOSTS', 'https://opensearch:9200')
22+ OPENSEARCH_HOSTNAME = os.getenv('OPENSEARCH_HOSTNAME', 'opensearch')
23+ OPENSEARCH_PORT = os.getenv('OPENSEARCH_PORT', '9200')
24+ OPENSEARCH_PROTOCOL = os.getenv('OPENSEARCH_PROTOCOL', 'https')
2325 OPENSEARCH_USER = os.getenv('OPENSEARCH_USER', 'admin')
2426 OPENSEARCH_PASSWORD = os.getenv('OPENSEARCH_PASSWORD', 'adminadmin')
2527 INDEX_NAME = os.getenv('INDEX_NAME', 'rag-documents')
3133 for i in range(60):
3234 try:
3335 response = requests.get(
34- f'https://{OPENSEARCH_HOST}:{OPENSEARCH_PORT}' ,
36+ OPENSEARCH_HOSTS ,
3537 auth=HTTPBasicAuth(OPENSEARCH_USER, OPENSEARCH_PASSWORD),
3638 verify=False,
3739 timeout=5
@@ -142,7 +144,7 @@ data:
142144 auth = HTTPBasicAuth(OPENSEARCH_USER, OPENSEARCH_PASSWORD)
143145
144146 # Create index pattern
145- response = requests.put (
147+ response = requests.post (
146148 f'{base_url}/api/saved_objects/index-pattern/{INDEX_NAME}?overwrite=true',
147149 json={"attributes": {"title": INDEX_NAME, "timeFieldName": "timestamp"}},
148150 auth=auth, headers=headers, timeout=10
@@ -202,9 +204,9 @@ data:
202204 return 1
203205
204206 client = OpenSearch(
205- hosts=[{'host': OPENSEARCH_HOST , 'port': OPENSEARCH_PORT}],
207+ hosts=[{'host': OPENSEARCH_HOSTNAME , 'port': OPENSEARCH_PORT}],
206208 http_auth=(OPENSEARCH_USER, OPENSEARCH_PASSWORD),
207- use_ssl=True ,
209+ use_ssl=OPENSEARCH_PROTOCOL == 'https' ,
208210 verify_certs=False,
209211 ssl_show_warn=False
210212 )
@@ -277,10 +279,6 @@ spec:
277279 pip install -q opensearch-py requests urllib3
278280 python -u /scripts/load.py
279281 env :
280- - name : OPENSEARCH_HOST
281- value : " opensearch"
282- - name : OPENSEARCH_PORT
283- value : " 9200"
284282 - name : OPENSEARCH_USER
285283 value : " admin"
286284 - name : OPENSEARCH_PASSWORD
@@ -292,6 +290,9 @@ spec:
292290 value : " rag-documents"
293291 - name : EMBEDDINGS_FILE
294292 value : " /data/stackable-docs-embeddings.json"
293+ envFrom :
294+ - configMapRef :
295+ name : opensearch
295296 volumeMounts :
296297 - name : script
297298 mountPath : /scripts
0 commit comments