{"record":{"id":"2f579053ee036c79","repo":"risingwavelabs/risingwave","slug":"no-value-find-in-sink-schema-index-is-0","errorCode":null,"errorMessage":"no value find in sink schema, index is 0","messagePattern":"no value find in sink schema, index is 0","errorType":"validation","errorClass":"SinkError","httpStatus":null,"severity":"error","filePath":"src/connector/src/sink/elasticsearch_opensearch/elasticsearch_opensearch_formatter.rs","lineNumber":57,"sourceCode":"    pub mem_size_b: usize,\n    pub routing_column: Option<String>,\n}\n\nimpl ElasticSearchOpenSearchFormatter {\n    pub fn new(\n        pk_indices: Vec<usize>,\n        schema: &Schema,\n        delimiter: Option<String>,\n        index_column: Option<usize>,\n        index: Option<String>,\n        routing_column: Option<usize>,\n    ) -> Result<Self> {\n        let key_format = if pk_indices.is_empty() {\n            let name = &schema\n                .fields()\n                .get(0)\n                .ok_or_else(|| {\n                    SinkError::ElasticSearchOpenSearch(anyhow!(\n                        \"no value find in sink schema, index is 0\"\n                    ))\n                })?\n                .name;\n            format!(\"{{{}}}\", name)\n        } else if pk_indices.len() == 1 {\n            let index = *pk_indices.get(0).unwrap();\n            let name = &schema\n                .fields()\n                .get(index)\n                .ok_or_else(|| {\n                    SinkError::ElasticSearchOpenSearch(anyhow!(\n                        \"no value find in sink schema, index is {:?}\",\n                        index\n                    ))\n                })?\n                .name;\n            format!(\"{{{}}}\", name)","sourceCodeStart":39,"sourceCodeEnd":75,"githubUrl":"https://github.com/risingwavelabs/risingwave/blob/6469eb736d691e8e9b8a419a57edd6429ca77417/src/connector/src/sink/elasticsearch_opensearch/elasticsearch_opensearch_formatter.rs#L39-L75","documentation":"When the sink has no primary key columns (`pk_indices` is empty), the formatter derives the document id/key from the first schema field. If the sink schema has zero fields (so `fields().get(0)` is None), construction fails with 'no value find in sink schema, index is 0'.","triggerScenarios":"Creating an Elasticsearch/OpenSearch sink whose schema is empty (no columns) while `pk_indices` is empty; the formatter's `new` falls into the empty-pk branch and cannot read field 0.","commonSituations":"Programmatically constructed sink with an empty schema, connector bug producing a schema-less sink, degenerate SELECT producing no columns.","solutions":["Ensure the sink schema has at least one column before creating the sink","Define a primary key on the sink so pk_indices is non-empty","Fix the upstream query so it selects at least one column","If this occurs with a valid schema, it indicates a planner/connector bug — file an issue"],"exampleFix":"// before\nCREATE SINK s FROM empty_view WITH (connector='elasticsearch');  -- empty_view has 0 columns\n// after\nCREATE SINK s FROM mv_with_columns WITH (connector='elasticsearch', primary_key = 'id');","handlingStrategy":"validation","validationCode":"fn check_schema_non_empty(schema: &Schema) -> Result<(), String> {\n    if schema.fields().is_empty() {\n        Err(\"sink schema has no columns; at least one is required\".into())\n    } else {\n        Ok(())\n    }\n}","typeGuard":null,"tryCatchPattern":null,"preventionTips":["Never create sinks from empty schemas; verify the upstream query selects columns","Define a primary key so document ids come from pk columns","Treat an empty-schema sink reaching the formatter as a bug and report it"],"tags":["rust","sink","formatter","schema","elasticsearch"],"backgroundTag":"index-out-of-range","analyzedSha":"6469eb736d691e8e9b8a419a57edd6429ca77417","analyzedAt":"2026-09-11T21:06:21.487Z","contentChangedAt":"2026-09-11T21:06:21.487Z","schemaVersion":2},"datasetVersion":"2026-09-14T16:17:12.679Z"}