langgenius/dify · error · ValueError
ELASTICSEARCH_USERNAME is required for self-hosted Elasticse
Error message
ELASTICSEARCH_USERNAME is required for self-hosted Elasticsearch
What it means
Raised by validate_elasticsearch_config (self-hosted branch) when ELASTICSEARCH_USERNAME is empty. Default is 'elastic', so this fires only when an operator explicitly blanks it.
Source
Thrown at api/configs/middleware/vdb/elasticsearch_config.py:70
description="Whether to retry requests on timeout (default is True)", default=True
)
ELASTICSEARCH_MAX_RETRIES: int = Field(
description="Maximum number of retry attempts (default is 10000)", default=10000
)
@model_validator(mode="after")
def validate_elasticsearch_config(self):
"""Validate Elasticsearch configuration based on deployment type."""
if self.ELASTICSEARCH_USE_CLOUD:
if not self.ELASTICSEARCH_CLOUD_URL:
raise ValueError("ELASTICSEARCH_CLOUD_URL is required when using Elastic Cloud")
if not self.ELASTICSEARCH_API_KEY:
raise ValueError("ELASTICSEARCH_API_KEY is required when using Elastic Cloud")
else:
if not self.ELASTICSEARCH_HOST:
raise ValueError("ELASTICSEARCH_HOST is required for self-hosted Elasticsearch")
if not self.ELASTICSEARCH_USERNAME:
raise ValueError("ELASTICSEARCH_USERNAME is required for self-hosted Elasticsearch")
if not self.ELASTICSEARCH_PASSWORD:
raise ValueError("ELASTICSEARCH_PASSWORD is required for self-hosted Elasticsearch")
return self
View on GitHub (pinned to ef8544b173)
Solutions
- Set ELASTICSEARCH_USERNAME (commonly 'elastic').
- Remove the empty override to restore the default.
- If the cluster truly needs no auth, switch to a fork or use a reverse proxy with auth.
Example fix
// before ELASTICSEARCH_USERNAME= // after ELASTICSEARCH_USERNAME=elastic
Defensive patterns
Strategy: validation
Validate before calling
def es_username_present(use_cloud: bool, username: str | None) -> bool:
return use_cloud or bool(username) Prevention
- Keep the ES username default unless you have a real alternative.
- Avoid clearing required credentials via templated envs.
- Use a pre-deploy config validator for self-hosted ES.
When it happens
Trigger: Setting ELASTICSEARCH_USERNAME='' while using self-hosted ES.
Common situations: Operator removes the username expecting anonymous auth, or a templated env blanks it.
Related errors
- ELASTICSEARCH_API_KEY is required when using Elastic Cloud
- ELASTICSEARCH_PASSWORD is required for self-hosted Elasticse
- ELASTICSEARCH_CLOUD_URL is required when using Elastic Cloud
- ELASTICSEARCH_HOST is required for self-hosted Elasticsearch
- KNOWLEDGE_FS_BASE_URL must not include credentials, query, o
AI-assisted analysis of langgenius/dify@ef8544b173 (2026-08-12).
Data as JSON: /api/errors/b82da0b08fcb76f1.
Report an issue: GitHub.