Fix index-level settings by moving them from elasticsearch.yml to an index template
This commit is contained in:
51
start.sh
51
start.sh
@@ -184,6 +184,54 @@ configure_elasticsearch() {
|
||||
chmod 755 /app/data /app/data/config
|
||||
}
|
||||
|
||||
# Create index template with optimized settings
|
||||
create_index_template() {
|
||||
echo "Creating default index template with optimized settings..."
|
||||
|
||||
# Wait a moment to ensure Elasticsearch is fully operational
|
||||
sleep 5
|
||||
|
||||
# Define the template JSON
|
||||
template_json=$(cat <<EOF
|
||||
{
|
||||
"index_patterns": ["*"],
|
||||
"template": {
|
||||
"settings": {
|
||||
"number_of_shards": 1,
|
||||
"number_of_replicas": 0,
|
||||
"merge": {
|
||||
"scheduler": {
|
||||
"max_thread_count": 1
|
||||
},
|
||||
"policy": {
|
||||
"floor_segment": "2mb",
|
||||
"max_merge_at_once": 4,
|
||||
"segments_per_tier": 8
|
||||
}
|
||||
}
|
||||
}
|
||||
},
|
||||
"priority": 1,
|
||||
"_meta": {
|
||||
"description": "Default template with Cloudron optimized settings"
|
||||
}
|
||||
}
|
||||
EOF
|
||||
)
|
||||
|
||||
# Apply the template
|
||||
curl -s -X PUT "http://localhost:9200/_index_template/cloudron_defaults" \
|
||||
-H "Content-Type: application/json" \
|
||||
-u "elastic:$ELASTIC_PASSWORD" \
|
||||
-d "$template_json" > /dev/null
|
||||
|
||||
if [ $? -eq 0 ]; then
|
||||
echo "Index template created successfully."
|
||||
else
|
||||
echo "Warning: Failed to create index template. Default settings may not be applied to new indices."
|
||||
fi
|
||||
}
|
||||
|
||||
# Set system limits - be more tolerant of container restrictions
|
||||
set_system_limits() {
|
||||
echo "Setting system limits for Elasticsearch..."
|
||||
@@ -278,6 +326,9 @@ start_elasticsearch() {
|
||||
cd $ES_HOME
|
||||
echo "y" | ES_JAVA_HOME=/app/data/jdk bin/elasticsearch-reset-password -u elastic -b -p "$ELASTIC_PASSWORD" --url "http://localhost:9200" || true
|
||||
|
||||
# Create index template with the settings we removed from elasticsearch.yml
|
||||
create_index_template
|
||||
|
||||
# Create credentials file
|
||||
cat > /app/data/credentials.txt << EOL
|
||||
Elasticsearch credentials:
|
||||
|
||||
Reference in New Issue
Block a user