Commit c2301bb8 authored by Andreas Düren's avatar Andreas Düren
Browse files

Fix index-level settings by moving them from elasticsearch.yml to an index template

parent efd6c2b0
Loading
Loading
Loading
Loading
+13 −10
Original line number Diff line number Diff line
@@ -30,7 +30,7 @@ xpack.security.authc.password_hashing.algorithm: bcrypt

# ----------------------------------- Memory ----------------------------------
# Memory locking to prevent swapping
bootstrap.memory_lock: true
bootstrap.memory_lock: false

# ---------------------------------- HTTP/REST API ---------------------------
http.cors.enabled: true
@@ -58,15 +58,18 @@ thread_pool.search.queue_size: 1000
# I/O optimization
bootstrap.system_call_filter: false

# Default index settings
index.number_of_shards: 1
index.number_of_replicas: 0

# Merge settings for better indexing performance
index.merge.scheduler.max_thread_count: 1 
index.merge.policy.floor_segment: 2mb
index.merge.policy.max_merge_at_once: 4
index.merge.policy.segments_per_tier: 8
# ---------------------------------- Index Templates ---------------------------
# Instead of setting index settings directly (which is not allowed), 
# we configure index templates that will be applied to new indices.
# Elasticsearch will automatically apply these templates to new indices.

# The following settings MUST be removed from this file:
# - index.number_of_shards
# - index.number_of_replicas
# - index.merge.scheduler.max_thread_count
# - index.merge.policy.floor_segment
# - index.merge.policy.max_merge_at_once
# - index.merge.policy.segments_per_tier

# Set processors based on container configuration
processors: ${PROCESSORS:1} 
 No newline at end of file
+51 −0
Original line number Diff line number Diff line
@@ -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: