Managing Keyspaces and Tables¶
You can perform keyspace and table operations, such as adding and getting information about keyspaces and tables, using these HTTP methods:
Keyspace Management Methods | URL |
---|---|
Retrieve information about all keyspaces | GET /{cluster_id}/keyspaces |
Retrieve information about a keyspace | GET /{cluster_id}/keyspaces/{ks_name} |
Update an existing keyspace | PUT /{cluster_id}/keyspaces/{ks_name} |
Drop a keyspace in a cluster | DELETE /{cluster_id}/keyspaces/{ks_name} |
Table Management Methods | |
Truncate a table | DELETE /{cluster_id}/data/{ks_name}/{cf_name} |
Drop a table itself | DELETE /{cluster_id}/keyspaces/{ks_name}/cf/{cf_name} |
Keyspace Management Methods¶
- GET /{cluster_id}/keyspaces¶
Retrieve all configured keyspaces in the cluster.
Path arguments: cluster_id – The ID of a cluster returned from
GET /cluster-configs
.Opt. params: - ksfields – Comma-delimited list of explicit keyspace properties to return.
- cffields – Comma-delimited list of explicit table properties to return.
Returns a dictionary where the key is the keyspace name, and the value is a dictionary of its properties. The list of properties for keyspaces and tables depends on the version of DataStax Enterprise that you’re running.
Example:
curl http://127.0.0.1:8888/Test_Cluster/keyspaces
Output:
{ "Keyspace1": { "strategy_options": { "replication_factor": 1 }, "column_families": { "SuperCounter1": { "is_in_memory": false, "create_query": "CREATE TABLE \"Keyspace1\".\"SuperCounter1\" (\ key blob, ...)", "solr_core": false }, ... } "durable_writes": true, "replica_placement_strategy": "org.apache.cassandra.locator.SimpleStrategy", "is_system": false }, ... }
- GET /{cluster_id}/keyspaces/{ks_name}¶
Retrieve information about a specific keyspace in the cluster.
Path arguments: - cluster_id – The ID of a cluster returned from
GET /cluster-configs
. - ks_name – The value of a ‘keyspace’ property in the output of
GET /{cluster_id}/keyspaces
.
Opt. params: - ksfields – Comma-delimited list of explicit keyspace properties to return.
- cffields – Comma-delimited list of explicit table properties to return.
Returns the dictionary containing all keyspace properties. The properties returned depend on the version of DataStax Enterprise.
Example
curl http://127.0.0.1:8888/Test_Cluster/keyspaces/Keyspace1
Output:
{ "strategy_options": { "replication_factor": 1 }, "column_families": { "SuperCounter1": { "is_in_memory": false, "create_query": "CREATE TABLE \"Keyspace1\".\"SuperCounter1\" (\ key blob, ...)", "solr_core": false }, ... } "durable_writes": true, "replica_placement_strategy": "org.apache.cassandra.locator.SimpleStrategy", "is_system": false }
- cluster_id – The ID of a cluster returned from
- PUT /{cluster_id}/keyspaces/{ks_name}¶
Update a keyspace.
Path arguments: - cluster_id – The ID of a cluster returned from
GET /cluster-configs
. - ks_name – The name of the keyspace to update.
Body: A JSON dictionary of all keyspace attributes, not just those you wish to change.
The JSON body should be similar to the one used when creating a keyspace.
Example
curl -X PUT http://127.0.0.1:8888/Test_Cluster/keyspaces/Keyspace1 -d '{ "strategy_class": "org.apache.cassandra.locator.SimpleStrategy", "strategy_options": {"replication_factor": "2"}, "durable_writes": true }'
- cluster_id – The ID of a cluster returned from
- DELETE /{cluster_id}/keyspaces/{ks_name}¶
Drop a keyspace from the cluster.
Path arguments: - cluster_id – The ID of a cluster returned from
GET /cluster-configs
. - ks_name – The name of the keyspace to delete.
Responses: 204 – Keyspace deleted successfully
Example
curl -X DELETE http://127.0.0.1:8888/Test_Cluster/keyspaces/test_ks
- cluster_id – The ID of a cluster returned from
Table Management Methods¶
- DELETE /{cluster_id}/data/{ks_name}/{cf_name}¶
Truncate a table. Deletes all data from the table but does not delete the table itself.
Path arguments: - cluster_id – The ID of a cluster returned from
GET /cluster-configs
. - ks_name – The name of the keyspace containing the table.
- cf_name – The name of the table to truncate.
Responses: 204 – Table truncated successfully
Returns null.
Example
curl -X DELETE http://127.0.0.1:8888/Test_Cluster/data/test_ks/users
- cluster_id – The ID of a cluster returned from
- DELETE /{cluster_id}/keyspaces/{ks_name}/cf/{cf_name}¶
Drop a table.
Path arguments: - cluster_id – The ID of a cluster returned from
GET /cluster-configs
. - ks_name – The name of the keyspace containing the table.
- cf_name – The name of the table to delete.
Responses: 204 – Table dropped successfully
Example
curl -X DELETE http://127.0.0.1:8888/Test_Cluster/keyspaces/test_ks/cf/users
- cluster_id – The ID of a cluster returned from