stacker.news/docker/opensearch/init-opensearch.sh
Edward Kung e4a2228d7c
NLP startup script + opensearch fixes (#2070)
* fix opensearch startup

* nlp setup script

* nlp setup documentation

* move script to ./scripts and update docs

---------

Co-authored-by: k00b <k00b@stacker.news>
2025-04-07 17:08:37 -05:00

43 lines
1.2 KiB
Bash
Executable File

#!/bin/bash
set -m
/usr/share/opensearch/opensearch-docker-entrypoint.sh &
# ---- Wait for OpenSearch to start
until curl -sS "http://localhost:9200/_cat/health?h=status" -ku admin:${OPENSEARCH_INITIAL_ADMIN_PASSWORD} | grep -q "green\|yellow"; do
echo "Waiting for OpenSearch to start..."
sleep 1
done
# ---- If index doesn't exist, create it with default settings
index_exists=$(curl -s -o /dev/null -w "%{http_code}" -I "http://localhost:9200/$OPENSEARCH_INDEX")
if [ "$index_exists" -eq 200 ]; then
echo "OpenSearch index $OPENSEARCH_INDEX already exists."
else
curl \
-H "Content-Type: application/json" \
-X PUT \
-d '{
"mappings": {
"properties": {
"text": {
"type": "text",
"analyzer": "english",
"fields": {"keyword":{"type":"keyword","ignore_above":256}}
},
"title": {
"type": "text",
"analyzer": "english",
"fields": {"keyword":{"type":"keyword","ignore_above":256}}
}}}}' \
"http://localhost:9200/$OPENSEARCH_INDEX" \
-ku admin:${OPENSEARCH_INITIAL_ADMIN_PASSWORD}
echo ""
echo "OpenSearch index $OPENSEARCH_INDEX created."
fi
fg