{"record":{"id":"b82da0b08fcb76f1","repo":"langgenius/dify","slug":"elasticsearch-username-is-required-for-self-hosted","errorCode":null,"errorMessage":"ELASTICSEARCH_USERNAME is required for self-hosted Elasticsearch","messagePattern":"ELASTICSEARCH_USERNAME is required for self-hosted Elasticsearch","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"api/configs/middleware/vdb/elasticsearch_config.py","lineNumber":70,"sourceCode":"        description=\"Whether to retry requests on timeout (default is True)\", default=True\n    )\n    ELASTICSEARCH_MAX_RETRIES: int = Field(\n        description=\"Maximum number of retry attempts (default is 10000)\", default=10000\n    )\n\n    @model_validator(mode=\"after\")\n    def validate_elasticsearch_config(self):\n        \"\"\"Validate Elasticsearch configuration based on deployment type.\"\"\"\n        if self.ELASTICSEARCH_USE_CLOUD:\n            if not self.ELASTICSEARCH_CLOUD_URL:\n                raise ValueError(\"ELASTICSEARCH_CLOUD_URL is required when using Elastic Cloud\")\n            if not self.ELASTICSEARCH_API_KEY:\n                raise ValueError(\"ELASTICSEARCH_API_KEY is required when using Elastic Cloud\")\n        else:\n            if not self.ELASTICSEARCH_HOST:\n                raise ValueError(\"ELASTICSEARCH_HOST is required for self-hosted Elasticsearch\")\n            if not self.ELASTICSEARCH_USERNAME:\n                raise ValueError(\"ELASTICSEARCH_USERNAME is required for self-hosted Elasticsearch\")\n            if not self.ELASTICSEARCH_PASSWORD:\n                raise ValueError(\"ELASTICSEARCH_PASSWORD is required for self-hosted Elasticsearch\")\n\n        return self\n","sourceCodeStart":52,"sourceCodeEnd":75,"githubUrl":"https://github.com/langgenius/dify/blob/ef8544b173fd6cd7a8e71df2cab576e52bebbfbc/api/configs/middleware/vdb/elasticsearch_config.py#L52-L75","documentation":"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.","triggerScenarios":"Setting ELASTICSEARCH_USERNAME='' while using self-hosted ES.","commonSituations":"Operator removes the username expecting anonymous auth, or a templated env blanks it.","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."],"exampleFix":"// before\nELASTICSEARCH_USERNAME=\n// after\nELASTICSEARCH_USERNAME=elastic","handlingStrategy":"validation","validationCode":"def es_username_present(use_cloud: bool, username: str | None) -> bool:\n    return use_cloud or bool(username)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["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."],"tags":["config","pydantic","elasticsearch","vdb","security","required-field"],"backgroundTag":null,"analyzedSha":"ef8544b173fd6cd7a8e71df2cab576e52bebbfbc","analyzedAt":"2026-08-12T05:15:17.394Z","schemaVersion":2},"datasetVersion":"2026-08-12T13:17:24.610Z"}