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

  1. Set ELASTICSEARCH_USERNAME (commonly 'elastic').
  2. Remove the empty override to restore the default.
  3. 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

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


AI-assisted analysis of langgenius/dify@ef8544b173 (2026-08-12). Data as JSON: /api/errors/b82da0b08fcb76f1. Report an issue: GitHub.