Drop an index
This Astra DB Serverless feature is currently in public preview. Development is ongoing, and the features and functionality are subject to change. Astra DB Serverless, and the use of such, is subject to the DataStax Preview Terms. The Data API tables commands are available through HTTP and the clients. If you use a client, tables commands are available only in client versions 2.0-preview or later. For more information, see Data API client upgrade guide. |
Deletes an index from a table in a Serverless (Vector) database.
Method signature
-
Python
-
TypeScript
-
Java
-
curl
database.drop_table_index(
name: str,
*,
keyspace: str,
if_exists: bool,
table_admin_timeout_ms: int,
request_timeout_ms: int,
timeout_ms: int,
) -> None
database.dropTableIndex(
name: string,
options?: {
ifExists?: boolean,
timeout?: number | TimeoutDescriptor,
keyspace?: string,
}): Promise<void>
void dropTableIndex(String indexName)
void dropTableIndex(
String indexName,
DropTableIndexOptions dropIndexOptions
)
curl -sS -L -X POST "ASTRA_DB_API_ENDPOINT/api/json/v1/ASTRA_DB_KEYSPACE" \
--header "Token: ASTRA_DB_APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"dropIndex": {
"name": "INDEX_NAME"
}
}'
Result
-
Python
-
TypeScript
-
Java
-
curl
Deletes the specified index.
Does not return anything.
Deletes the specified index.
Returns a promise that resolves once the operation completes.
Deletes the specified index.
Does not return anything.
Deletes the specified index from the a table.
If the command succeeds, the response indicates the success.
Example response:
{
"status": {
"ok": 1
}
}
Parameters
-
Python
-
TypeScript
-
Java
-
curl
Name | Type | Summary |
---|---|---|
|
|
The name of the index to delete. |
|
|
The keyspace where you created the index. If unspecified, the database’s default keyspace setting is used. |
|
|
If If |
|
|
A timeout, in milliseconds, to impose on the underlying API request.
If not provided, the |
Name | Type | Summary |
---|---|---|
|
|
The name of the index to delete. |
|
|
The options for this operation. |
Options (TableDropIndexOptions
):
Name | Type | Summary |
---|---|---|
|
|
If If |
|
|
The client-side timeout for this operation. |
Name | Type | Summary |
---|---|---|
|
|
Name of the index to drop |
|
Specialization of index deletion options, including If If |
Name | Type | Summary |
---|---|---|
|
|
The Data API command to delete an index from a Serverless (Vector) database. It acts as a container for all the attributes and settings required to delete the index. |
|
|
The name of the index to delete. |
Examples
The following examples demonstrate how to delete an index from a table.
-
Python
-
TypeScript
-
Java
-
curl
Drop an index in a database:
database.drop_table_index("score_index")
Example:
from astrapy import DataAPIClient
client = DataAPIClient("TOKEN")
database = client.get_database("API_ENDPOINT")
from astrapy.constants import SortMode
from astrapy.info import (
CreateTableDefinition,
ColumnType,
)
# Create table
my_table = database.create_table(
"games",
definition=(
CreateTableDefinition.builder()
.add_column("match_id", ColumnType.TEXT)
.add_column("round", ColumnType.TINYINT)
.add_vector_column("m_vector", dimension=3)
.add_column("score", ColumnType.INT)
.add_column("when", ColumnType.TIMESTAMP)
.add_column("winner", ColumnType.TEXT)
.add_set_column("fighters", ColumnType.UUID)
.add_partition_by(["match_id"])
.add_partition_sort({"round": SortMode.ASCENDING})
.build()
),
)
from astrapy.info import TableIndexOptions
# Create index
my_table.create_index(
"score_index",
column="score",
)
# Drop an index from the keyspace:
database.drop_table_index("score_index")
# Drop an index, unless it does not exist already:
database.drop_table_index("score_index", if_exists=True)
Drop an index in a database:
await db.dropTableIndex('score_index');
Example:
Full script
import { CreateTableDefinition, DataAPIClient, SomeRow } from '@datastax/astra-db-ts';
// Instantiate the client and connect to the database
const client = new DataAPIClient();
const db = client.db(process.env.CLIENT_DB_URL!, { token: process.env.CLIENT_DB_TOKEN! });
// Create table schema using bespoke Data API table definition syntax.
// For information about table definition and data types, see the documentation for createTable.
const TableDefinition = <const>{
columns: {
matchId: 'text'
round: 'tinyint',
mVector: { type: 'vector', dimension: 3 },
score: 'int',
when: 'timestamp',
winner: 'text',
fighters: { type: 'set', valueType: 'uuid' },
},
primaryKey: {
partitionBy: ['matchId'],
partitionSort: { round: 1 },
},
} satisfies CreateTableDefinition;
(async function () {
// Create an untyped table if a 'games' table doesn't already exist
const table = await db.createTable<SomeRow>('games', { definition: TableDefinition, ifNotExists: true });
// Create a secondary index on the 'score' column with default options.
// Errors if a 'score_idx' index already exists in the working keyspace.
await table.createIndex('score_idx', 'score');
// Create a secondary index on the 'winner' column with case-insensitivity
// Because 'ifNotExists: true', the command does not throw an error
// if the working keyspace already has an index named 'winner_idx'.
await table.createIndex('winner_idx', 'winner', {
options: {
caseSensitive: false,
},
ifNotExists: true,
});
// Case insensitive indexes ignore case when querying.
// Insert a row with upper case and lower case characters,
// and then query the row.
// findOne returns a match because 'winner_idx' is case-insensitive.
await table.insertOne({ matchId: '01', round: 0, winner: 'Gray Tist' });
await table.findOne({ winner: 'gray tist' }).then(console.log);
// Create a vector index on the 'mVector' column with cosine similarity (default).
// Errors if an 'm_vector_idx' index already exists in the working keyspace.
await table.createVectorIndex('m_vector_idx', 'mVector');
// Create a vector index on the 'mVector' column with dot-product similarity.
// Because 'ifNotExists: true', the command does not throw an error
// if the working keyspace already has an index named 'm_vector_idx'.
await table.createVectorIndex('m_vector_idx', 'mVector', {
options: {
metric: 'dot_product',
},
ifNotExists: true,
});
// Drop the index so you can recreate it with different options.
await db.dropTableIndex('m_vector_idx');
// Create the vector index with dot-product similarity and a source model.
// For accurate searches, use a source model and metric that are compatible with your vectors.
await table.createVectorIndex('m_vector_idx', 'mVector', {
options: {
metric: 'dot_product',
sourceModel: 'ada002',
},
});
// Vector indexes allow you to perform vector searches.
// Insert a row with a vector, and then run a vector search on the table.
await table.insertOne({ matchId: '01', round: 0, mVector: [0.2, -0.3, -0.5] });
await table.findOne({}, { sort: { mVector: [0.2, -0.3, -0.5] } }).then(console.log);
// Get detailed information about the indexes
// Returns information like [{ name: 'score_idx', definition: { column: 'score', options: {} } }, ...]
await table.listIndexes().then(console.log);
// Get index names only.
// Returns information like ['score_idx', 'winner_idx', 'm_vector_idx', ...]
await table.listIndexes({ nameOnly: true }).then(console.log);
// Drop an index from a database's working keyspace without checking if the index exists.
// If there is no match, the command succeeds but does nothing.
// If there is a match, the named index is deleted.
await db.dropTableIndex('score_idx');
// Drop an index from a database's working keyspace if the index exists.
// Errors if there is no match.
await db.dropTableIndex('score_idx', { ifExists: true });
// Uncomment the following line to drop the table and any related indexes.
// await table.drop();
})();
// Drop an index from a database's working keyspace without checking if the index exists.
// If there is no match, the command succeeds but does nothing.
// If there is a match, the named index is deleted.
await db.dropTableIndex('score_idx');
// Drop an index from a database's working keyspace if the index exists.
// Errors if there is no match.
await db.dropTableIndex('score_idx', { ifExists: true });
Drop an index from a database:
database.dropTableIndex("score_index");
Drop an index with command options:
DropTableIndexOptions options = new DropTableIndexOptions()
.ifExists(true)
.keyspace("KEYSPACE_NAME")
.timeout(Duration.ofSeconds(5));
database
.dropTableIndex("winner_index", options);
Example:
package com.datastax.astra.client.database;
import com.datastax.astra.client.DataAPIClients;
import com.datastax.astra.client.databases.Database;
import com.datastax.astra.client.tables.commands.options.DropTableIndexOptions;
import com.datastax.astra.client.tables.commands.options.DropTableOptions;
import static java.time.Duration.ofSeconds;
public class DropTableIndex {
public static void main(String[] args) {
// Database astraDb = new DataAPIClient(token).getDatabase(endpoint);
Database db = DataAPIClients.localDbWithDefaultKeyspace();
// Drop without options
db.dropTableIndex("games");
// Adding a timestamp
DropTableIndexOptions options = new DropTableIndexOptions()
.ifExists(false)
.keyspace("KEYSPACE_NAME")
.timeout(ofSeconds(5));
db.dropTableIndex("games", options);
}
}
curl -sS -L -X POST "ASTRA_DB_API_ENDPOINT/api/json/v1/ASTRA_DB_KEYSPACE" \
--header "Token: ASTRA_DB_APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"dropIndex": {
"name": "INDEX_NAME"
}
}'
Example:
curl -sS -L -X POST "ASTRA_DB_API_ENDPOINT/api/json/v1/default_keyspace" \
--header "Token: ASTRA_DB_APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"dropIndex": {
"name": "index_metadata_students"
}
}'
Client reference
-
Python
-
TypeScript
-
Java
-
curl
For more information, see the client reference.
For more information, see the client reference.
For more information, see the client reference.
Client reference documentation is not applicable for HTTP.