{"record":{"id":"561f32b57f698418","repo":"apache/seatunnel","slug":"truncate-collection-error","errorCode":"TRUNCATE_COLLECTION_ERROR","errorMessage":"TRUNCATE_COLLECTION_ERROR.getDescription()","messagePattern":"TRUNCATE_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":260,"sourceCode":"    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\");\n        try {\n            tsClient.collections(collection).documents().delete(deleteDocumentsParameters);\n        } catch (Exception e) {\n            log.error(TRUNCATE_COLLECTION_ERROR.getDescription());\n            throw new TypesenseConnectorException(\n                    TRUNCATE_COLLECTION_ERROR, TRUNCATE_COLLECTION_ERROR.getDescription());\n        }\n        return true;\n    }\n\n    public boolean deleteCollectionData(String collection, String id) {\n        try {\n            tsClient.collections(collection).documents(id).delete();\n        } catch (Exception e) {\n            log.error(DELETE_COLLECTION_ERROR.getDescription());\n            throw new TypesenseConnectorException(\n                    DELETE_COLLECTION_ERROR, DELETE_COLLECTION_ERROR.getDescription());\n        }\n        return true;\n    }\n\n    public long collectionDocNum(String collection) {\n        SearchParameters q = new SearchParameters().q(\"*\");","sourceCodeStart":242,"sourceCodeEnd":278,"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#L242-L278","documentation":"TypesenseClient.truncateCollectionData() empties a collection by deleting all documents using a filter 'id:!=1||id:=1'; failures from the bulk delete API are rethrown as TypesenseConnectorException with TRUNCATE_COLLECTION_ERROR.","triggerScenarios":"Calling truncateCollectionData(collection) when the collection no longer exists (404 on the documents endpoint), the API key cannot delete documents, or the delete filter is rejected by the Typesense version in use.","commonSituations":"Truncate/overwrite write modes on a collection dropped concurrently; older Typesense servers that don't support the filter_by delete syntax; permission-restricted keys.","solutions":["Verify the collection exists before truncating; create it if the 404 is expected in your flow","Ensure the API key has document-delete permissions","Confirm the Typesense server version supports filter_by-based bulk document deletion","Attach the original exception when rethrowing to see Typesense's precise error"],"exampleFix":"// before\n} catch (Exception e) {\n    log.error(TRUNCATE_COLLECTION_ERROR.getDescription());\n    throw new TypesenseConnectorException(TRUNCATE_COLLECTION_ERROR, TRUNCATE_COLLECTION_ERROR.getDescription());\n}\n// after\n} catch (Exception e) {\n    log.error(TRUNCATE_COLLECTION_ERROR.getDescription(), e);\n    throw new TypesenseConnectorException(TRUNCATE_COLLECTION_ERROR, TRUNCATE_COLLECTION_ERROR.getDescription(), e);\n}","handlingStrategy":"retry","validationCode":"if (!client.collectionExists(collection)) {\n    throw new IllegalStateException(\"Cannot truncate non-existent collection: \" + collection);\n}","typeGuard":null,"tryCatchPattern":"try {\n    client.truncateCollectionData(collection);\n} catch (TypesenseConnectorException e) {\n    // bounded exponential-backoff retry; verify collection exists and key permissions\n}","preventionTips":["Check collection existence before truncation","Ensure delete permission on documents for the API key","Confirm server version supports filter_by bulk delete","Retry transient failures; avoid truncating collections other jobs may be writing to"],"tags":["typesense","truncate","delete-documents"],"backgroundTag":"database-write-failed","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"}