stacker.news/docker/opensearch/init-opensearch.sh
m0wer f12c03198d
Exact search (#2135)
* feat: add exact search for quoted phrases/words

* feat: get some highlighting for exact search

* feat: Add exact search for title and text fields in OpenSearch

* simplify and make it work with nlp script

---------

Co-authored-by: Keyan <34140557+huumn@users.noreply.github.com>
Co-authored-by: k00b <k00b@stacker.news>
2025-05-15 09:11:58 -05:00

59 lines
1.5 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},
"exact": {
"type": "text",
"analyzer": "standard"
}
}
},
"title": {
"type": "text",
"analyzer": "english",
"fields": {
"keyword": {"type": "keyword", "ignore_above": 256},
"exact": {
"type": "text",
"analyzer": "standard"
}
}
}
}
}
}' \
"http://localhost:9200/$OPENSEARCH_INDEX" \
-ku admin:${OPENSEARCH_INITIAL_ADMIN_PASSWORD}
echo ""
echo "OpenSearch index $OPENSEARCH_INDEX created."
fi
fg