{"record":{"id":"00e547c94aae2c2a","repo":"langgenius/dify","slug":"elasticsearch-api-key-is-required-when-using-elast","errorCode":null,"errorMessage":"ELASTICSEARCH_API_KEY is required when using Elastic Cloud","messagePattern":"ELASTICSEARCH_API_KEY is required when using Elastic Cloud","errorType":"validation","errorClass":"ValueError","httpStatus":null,"severity":"error","filePath":"api/configs/middleware/vdb/elasticsearch_config.py","lineNumber":65,"sourceCode":"    )\n    ELASTICSEARCH_REQUEST_TIMEOUT: int = Field(\n        description=\"Request timeout in milliseconds (default is 100000)\", default=100000\n    )\n    ELASTICSEARCH_RETRY_ON_TIMEOUT: bool = Field(\n        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":47,"sourceCodeEnd":75,"githubUrl":"https://github.com/langgenius/dify/blob/ef8544b173fd6cd7a8e71df2cab576e52bebbfbc/api/configs/middleware/vdb/elasticsearch_config.py#L47-L75","documentation":"Raised by validate_elasticsearch_config when Elastic Cloud is enabled but ELASTICSEARCH_API_KEY is empty. Elastic Cloud authenticates via API key, not username/password.","triggerScenarios":"ELASTICSEARCH_USE_CLOUD=true with ELASTICSEARCH_CLOUD_URL set but ELASTICSEARCH_API_KEY unset.","commonSituations":"Provisioning cloud URL but deferring API key creation, or assuming username/password carry over to cloud mode.","solutions":["Generate an API key in the Elastic Cloud console and set ELASTICSEARCH_API_KEY.","If you intend self-hosted auth, set ELASTICSEARCH_USE_CLOUD=false and use username/password."],"exampleFix":"// before\nELASTICSEARCH_USE_CLOUD=true\nELASTICSEARCH_CLOUD_URL=https://xxx.es.region.aws.found.io:443\n// after\nELASTICSEARCH_USE_CLOUD=true\nELASTICSEARCH_CLOUD_URL=https://xxx.es.region.aws.found.io:443\nELASTICSEARCH_API_KEY=<elastic-cloud-api-key>","handlingStrategy":"validation","validationCode":"def es_cloud_api_key_present(use_cloud: bool, api_key: str | None) -> bool:\n    return (not use_cloud) or bool(api_key)","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Provision the Elastic Cloud API key before enabling cloud mode.","Inject the key via a secrets manager.","Do not assume username/password carries over to cloud."],"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"}