{"record":{"id":"6b4983f6fc614e2e","repo":"apache/seatunnel","slug":"create-collection-error","errorCode":"CREATE_COLLECTION_ERROR","errorMessage":"CREATE_COLLECTION_ERROR.getDescription()","messagePattern":"CREATE_COLLECTION_ERROR\\.getDescription\\(\\)","errorType":"error_code","errorClass":"TypesenseConnectorException","httpStatus":null,"severity":"error","filePath":"seatunnel-connectors-v2/connector-typesense/src/main/java/org/apache/seatunnel/connectors/seatunnel/typesense/client/TypesenseClient.java","lineNumber":237,"sourceCode":"\n    public boolean createCollection(String collection) {\n        if (collectionExists(collection)) {\n            return true;\n        }\n        List<Field> fields = new ArrayList<>();\n        fields.add(new Field().name(\".*\").type(FieldTypes.AUTO));\n        return createCollection(collection, fields);\n    }\n\n    public boolean createCollection(String collection, List<Field> fields) {\n        CollectionSchema collectionSchema = new CollectionSchema();\n        collectionSchema.name(collection).fields(fields).enableNestedFields(true);\n        try {\n            tsClient.collections().create(collectionSchema);\n            return true;\n        } catch (Exception e) {\n            log.error(CREATE_COLLECTION_ERROR.getDescription());\n            throw new TypesenseConnectorException(\n                    CREATE_COLLECTION_ERROR, CREATE_COLLECTION_ERROR.getDescription());\n        }\n    }\n\n    public boolean dropCollection(String collection) {\n        try {\n            tsClient.collections(collection).delete();\n            return true;\n        } catch (Exception e) {\n            log.error(DROP_COLLECTION_ERROR.getDescription());\n            throw new TypesenseConnectorException(\n                    DROP_COLLECTION_ERROR, DROP_COLLECTION_ERROR.getDescription());\n        }\n    }\n\n    public boolean truncateCollectionData(String collection) {\n        DeleteDocumentsParameters deleteDocumentsParameters = new DeleteDocumentsParameters();\n        deleteDocumentsParameters.filterBy(\"id:!=1||id:=1\");","sourceCodeStart":219,"sourceCodeEnd":255,"githubUrl":"https://github.com/apache/seatunnel/blob/cf67b549a7a6c35fa0beb12d83c62892427ea919/seatunnel-connectors-v2/connector-typesense/src/main/java/org/apache/seatunnel/connectors/seatunnel/typesense/client/TypesenseClient.java#L219-L255","documentation":"TypesenseClient.createCollection() calls the Typesense create-collection API; a failure is rethrown as TypesenseConnectorException with CREATE_COLLECTION_ERROR. This happens when the collection already exists or the API rejects the schema.","triggerScenarios":"Calling createCollection(collection) when a collection with that name already exists (Typesense returns 409), the field schema is invalid (bad field types, missing 'name' field type), or the API key lacks collection-creation rights.","commonSituations":"Re-running a job/schema-sync without drop-first so the collection already exists; schema fields mapping to invalid Typesense types; read-only API keys in config.","solutions":["Check collectionExists(collection) before creating, or catch the 409 and treat it as success/idempotent","Validate the generated field list (each field needs a valid name and Typesense-supported type)","Ensure the API key has admin/collection-write permissions","Attach the cause to the rethrown exception to see Typesense's specific error message"],"exampleFix":"// before\npublic boolean createCollection(String collection) {\n    ... build schema ...\n    tsClient.collections().create(collectionSchema);\n    return true;\n}\n// after\npublic synchronized boolean createCollection(String collection) {\n    if (collectionExists(collection)) {\n        return true;\n    }\n    ... build schema ...\n    tsClient.collections().create(collectionSchema);\n    return true;\n}","handlingStrategy":"validation","validationCode":"if (client.collectionExists(collection)) {\n    return; // already created — skip create to avoid conflict error\n}","typeGuard":null,"tryCatchPattern":"try {\n    client.createCollection(collection);\n} catch (TypesenseConnectorException e) {\n    // check if cause is 409 already-exists and treat as success, otherwise rethrow\n}","preventionTips":["Make create flows idempotent: check existence first or tolerate already-exists","Validate mapped field types are valid Typesense types before create","Use API keys with collection-creation permission","Drop the collection before re-running schema-sync jobs when a clean create is intended"],"tags":["typesense","create-collection","conflict"],"backgroundTag":"file-already-exists","analyzedSha":"cf67b549a7a6c35fa0beb12d83c62892427ea919","analyzedAt":"2026-09-10T21:44:55.265Z","contentChangedAt":"2026-09-10T21:44:55.265Z","schemaVersion":2},"datasetVersion":"2026-09-23T08:17:48.524Z"}