Create a text index

Tables with the Data API are 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.

Hybrid search, lexical search, and reranking are 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.

Creates a new text index for a text or ascii column in a table.

You must create a text index if you want to perform lexicographical matching on the column.

To index a text column for sorting and filtering other than lexicographical matching, see Create an index instead.

To manage indexes, your application token must have the same level of permissions that you need to manage tables.

Ready to write code? See the examples for this method to get started. If you are new to the Data API, check out the quickstart.

Result

  • Python

  • TypeScript

  • Java

  • curl

Creates a text index for the specified column.

Does not return anything.

Creates a text index for the specified column.

Returns a promise that resolves once the operation completes.

Creates a text index for the specified column.

Does not return anything.

Creates a text index for the specified column.

If the command succeeds, the response indicates the success.

Example response:

{
  "status": {
    "ok": 1
  }
}

Parameters

  • Python

  • TypeScript

  • Java

  • curl

Use the create_text_index method, which belongs to the astrapy.table.Table class.

Method signature
create_text_index(
  name: str,
  column: str,
  *,
  definition: TableTextIndexDefinition | dict[str, Any],
  options: TableTextIndexOptions | dict[str, Any],
  if_not_exists: bool,
  table_admin_timeout_ms: int,
  request_timeout_ms: int,
  timeout_ms: int,
) -> None
Name Type Summary

name

str

The name of the index.

Index names for tables must follow these rules:

  • Must be unique within the keyspace

  • Can contain letters, numbers, and underscores

  • Must have a length of 1 to 100 characters

column

str

The name of the table column on which to create the text index.

The column must be a text or ascii column.

The column name must use snake case, not camel case.

definition

TableTextIndexDefinition | dict

Optional. Specifies the indexed column and index options. If you use this parameter, the column and options parameters are not accepted.

options

TableTextIndexOptions | dict

Optional. Specifies index options.

If passed, it must be an instance of TableTextIndexOptions or an equivalent dictionary.

The only attribute of TableTextIndexOptions is analyzer: either a string describing a built-in analyzer, or a JSON object describing an analyzer configuration.

Strings must be one of the supported built-in analyzers.

JSON objects must follow the specifications in Find data with CQL analyzers.

See the examples for usage.

Default: analyzer="standard", which corresponds to the standard Apache Lucene™ analyzer.

if_not_exists

bool

Optional. Whether the command should silently succeed even if an index with the given name already exists in the keyspace and no new index was created.

This option only checks index names. It does not check index definitions.

Default: false

table_admin_timeout_ms

int

Optional. A timeout, in milliseconds, to impose on the underlying API request. If not provided, the Table defaults apply.

This parameter is aliased as request_timeout_ms and timeout_ms for convenience.

Use the createTextIndex method, which belongs to the Table class.

Method signature
async createTextIndex(
  name: string,
  column: keyof Schema | Partial<Record<keyof Schema, string>>,
  options?: {
    options?: {
      analyzer?: string | Record<string, unknown>,
    },
    ifNotExists?: boolean,
    timeout?: number | TimeoutDescriptor,
  },
): void
Name Type Summary

name

string

The name of the index.

Index names for tables must follow these rules:

  • Must be unique within the keyspace

  • Can contain letters, numbers, and underscores

  • Must have a length of 1 to 100 characters

column

string

The name of the table column on which to create the text index.

The column must be a text or ascii column.

The column name must use snake case, not camel case.

options

TableCreateTextIndexOptions

Optional. The options for this operation. See Properties of options for more details.

Properties of options
Name Type Summary

options.analyzer

string or object

Optional. A string describing a built-in analyzer, or a JSON object describing an analyzer configuration.

Strings must be one of the supported built-in analyzers.

JSON objects must follow the specifications in Find data with CQL analyzers.

See the examples for usage.

Default: "standard", which corresponds to the standard Apache Lucene™ analyzer.

ifNotExists

boolean

Optional. Whether the command should silently succeed even if an index with the given name already exists in the keyspace and no new index was created.

This option only checks index names. It does not check index definitions.

Default: false

timeout

number | TimeoutDescriptor

A timeout, in milliseconds, to impose on the underlying API request.

Use the createTextIndex method, which belongs to the com.datastax.astra.client.tables.Table class.

Method signature
void createTextIndex(
  String indexName,
  String columnName
)
void createTextIndex(
  String indexName,
  TableTextIndexDefinition indexDefinition
)
void createIndex(
  String indexName,
  TableTextIndexDefinition indexDefinition,
  CreateTextIndexOptions indexOptions
)
Name Type Summary

name

string

The name of the index.

Index names for tables must follow these rules:

  • Must be unique within the keyspace

  • Can contain letters, numbers, and underscores

  • Must have a length of 1 to 100 characters

definition

TableTextIndexDefinition

The index definition. See Methods of the TableTextIndexDefinition constructor for more details.

options

CreateTextIndexOptions

The options for this operation. See Methods of the CreateTextIndexOptions constructor for more details.

Methods of the TableTextIndexDefinition constructor
Method Type Summary

column

string

The name of the table column on which to create the text index.

The column must be a text or ascii column.

The column name must use snake case, not camel case.

analyzer

string or object or Analyzer

Optional. A string describing a built-in analyzer, or a JSON object or Analyzer describing an analyzer configuration.

Strings must be one of the supported built-in analyzers.

JSON objects must follow the specifications in Find data with CQL analyzers.

See the examples for usage.

Default: "standard", which corresponds to the standard Apache Lucene™ analyzer.

Methods of the CreateTextIndexOptions constructor
Method Type Summary

ifNotExists

boolean

Optional. Whether the command should silently succeed even if an index with the given name already exists in the keyspace and no new index was created.

This option only checks index names. It does not check index definitions.

Default: false

Use the createTextIndex command.

Command signature
curl -sS -L -X POST "API_ENDPOINT/api/json/v1/KEYSPACE_NAME/TABLE_NAME" \
--header "Token: APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
  "createTextIndex": {
    "name": "INDEX_NAME",
    "definition": {
      "column": "COLUMN_NAME",
      "options": {
        "analyzer": ANALYZER
      }
    },
    "options": {
      "ifNotExists": BOOLEAN
    }
  }
}'
Name Type Summary

name

string

The name of the index.

Index names for tables must follow these rules:

  • Must be unique within the keyspace

  • Can contain letters, numbers, and underscores

  • Must have a length of 1 to 100 characters

definition

object

Optional. The index definition. See Properties of definition for more details.

options

object

Optional. The options for this operation. See Properties of options for more details.

Properties of definition
Name Type Summary

column

string

The name of the table column on which to create the text index.

The column must be a text or ascii column.

The column name must use snake case, not camel case.

options.analyzer

string or object

Optional. A string describing a built-in analyzer, or a JSON object describing an analyzer configuration.

Strings must be one of the supported built-in analyzers.

JSON objects must follow the specifications in Find data with CQL analyzers.

See the examples for usage.

Default: "standard", which corresponds to the standard Apache Lucene™ analyzer.

Properties of options
Name Type Summary

ifNotExists

boolean

Optional. Whether the command should silently succeed even if an index with the given name already exists in the keyspace and no new index was created.

This option only checks index names. It does not check index definitions.

Default: false

Examples

The following examples demonstrate how to create a text index.

Create a text index and use the default analyzer

If you don’t specify an analyzer, the index will use the standard Apache Lucene™ analyzer.

  • Python

  • TypeScript

  • Java

  • curl

from astrapy import DataAPIClient

# Get an existing table
client = DataAPIClient("APPLICATION_TOKEN")
database = client.get_database("API_ENDPOINT")
table = database.get_table("TABLE_NAME")

# Index a column
table.create_text_index("example_index_name", column="example_text_column")
import { DataAPIClient } from "@datastax/astra-db-ts";

// Get an existing table
const client = new DataAPIClient("APPLICATION_TOKEN");
const database = client.db("API_ENDPOINT");
const table = database.table("TABLE_NAME");

// Index a column
(async function () {
  await table.createTextIndex("example_index_name", "example_text_column");
})();
import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.tables.Table;
import com.datastax.astra.client.tables.definition.rows.Row;

public class Example {

  public static void main(String[] args) {
    // Get an existing table
    Table<Row> table =
        new DataAPIClient("APPLICATION_TOKEN")
            .getDatabase("API_ENDPOINT")
            .getTable("TABLE_NAME");

    // Index a column
    table.createTextIndex("example_index_name", "example_text_column");
  }
}
curl -sS -L -X POST "API_ENDPOINT/api/json/v1/KEYSPACE_NAME/TABLE_NAME" \
  --header "Token: APPLICATION_TOKEN" \
  --header "Content-Type: application/json" \
  --data '{
  "createTextIndex": {
    "name": "example_index_name",
    "definition": {
      "column": "example_text_column"
    }
  }
}'

Create a text index and specify the analyzer as a string

You can use a string to specify the analyzer. Strings must be one of the supported built-in analyzers.

Alternatively, you can describe the analyzer configuration as a JSON object as demonstrated in Create a text index and specify the analyzer as an object.

  • Python

  • TypeScript

  • Java

  • curl

from astrapy import DataAPIClient
from astrapy.info import TableTextIndexOptions

# Get an existing table
client = DataAPIClient("APPLICATION_TOKEN")
database = client.get_database("API_ENDPOINT")
table = database.get_table("TABLE_NAME")

# Index a column
table.create_text_index(
    "example_index_name",
    column="example_text_column",
    options=TableTextIndexOptions(
        analyzer="english",
    ),
)
import { DataAPIClient } from "@datastax/astra-db-ts";

// Get an existing table
const client = new DataAPIClient("APPLICATION_TOKEN");
const database = client.db("API_ENDPOINT");
const table = database.table("TABLE_NAME");

// Index a column
(async function () {
  await table.createTextIndex("example_index_name", "example_text_column", {
    options: {
      analyzer: "english",
    },
  });
})();
import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.core.lexical.AnalyzerTypes;
import com.datastax.astra.client.tables.Table;
import com.datastax.astra.client.tables.definition.indexes.TableTextIndexDefinition;
import com.datastax.astra.client.tables.definition.rows.Row;

public class Example {

  public static void main(String[] args) {
    // Get an existing table
    Table<Row> table =
        new DataAPIClient("APPLICATION_TOKEN")
            .getDatabase("API_ENDPOINT")
            .getTable("TABLE_NAME");

    // Index a column
    TableTextIndexDefinition definition =
        new TableTextIndexDefinition()
            .column("example_text_column")
            .analyzer(AnalyzerTypes.ENGLISH);
    table.createTextIndex("example_index_name", definition);
  }
}
curl -sS -L -X POST "API_ENDPOINT/api/json/v1/KEYSPACE_NAME/TABLE_NAME" \
  --header "Token: APPLICATION_TOKEN" \
  --header "Content-Type: application/json" \
  --data '{
  "createTextIndex": {
    "name": "example_index_name",
    "definition": {
      "column": "example_text_column",
      "options": {
        "analyzer": "english"
      }
    }
  }
}'

Create a text index and specify the analyzer as an object

You can describe the analyzer configuration as a JSON object. JSON objects must follow the specifications in Find data with CQL analyzers.

The following example uses a configuration suitable for English text. Alternatively, you can use the string shorthand demonstrated in Create a text index and specify the analyzer as a string.

  • Python

  • TypeScript

  • Java

  • curl

from astrapy import DataAPIClient
from astrapy.info import TableTextIndexOptions

# Get an existing table
client = DataAPIClient("APPLICATION_TOKEN")
database = client.get_database("API_ENDPOINT")
table = database.get_table("TABLE_NAME")

# Index a column
table.create_text_index(
    "example_index_name",
    column="example_text_column",
    options=TableTextIndexOptions(
        analyzer={
            "tokenizer": {"name": "standard", "args": {}},
            "filters": [
                {"name": "lowercase"},
                {"name": "stop"},
                {"name": "porterstem"},
                {"name": "asciifolding"},
            ],
            "charFilters": [],
        },
    ),
)
import { DataAPIClient } from "@datastax/astra-db-ts";

// Get an existing table
const client = new DataAPIClient("APPLICATION_TOKEN");
const database = client.db("API_ENDPOINT");
const table = database.table("TABLE_NAME");

// Index a column
(async function () {
  await table.createTextIndex("example_index_name", "example_text_column", {
    options: {
      analyzer: {
        tokenizer: {
          name: "standard",
          args: {},
        },
        filters: [
          {
            name: "lowercase",
          },
          {
            name: "stop",
          },
          {
            name: "porterstem",
          },
          {
            name: "asciifolding",
          },
        ],
        charFilters: [],
      },
    },
  });
})();
import static com.datastax.astra.client.core.lexical.AnalyzerTypes.STANDARD;

import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.core.lexical.Analyzer;
import com.datastax.astra.client.tables.Table;
import com.datastax.astra.client.tables.definition.indexes.TableTextIndexDefinition;
import com.datastax.astra.client.tables.definition.rows.Row;

public class Example {

  public static void main(String[] args) {
    // Get an existing table
    Table<Row> table =
        new DataAPIClient("APPLICATION_TOKEN")
            .getDatabase("API_ENDPOINT")
            .getTable("TABLE_NAME");

    // Index a column
    Analyzer analyzer =
        new Analyzer()
            .tokenizer(STANDARD.getValue())
            .addFilter("lowercase")
            .addFilter("stop")
            .addFilter("porterstem")
            .addFilter("asciifolding");
    TableTextIndexDefinition definition =
        new TableTextIndexDefinition().column("example_text_column").analyzer(analyzer);
    table.createTextIndex("example_index_name", definition);
  }
}
curl -sS -L -X POST "API_ENDPOINT/api/json/v1/KEYSPACE_NAME/TABLE_NAME" \
  --header "Token: APPLICATION_TOKEN" \
  --header "Content-Type: application/json" \
  --data '{
  "createTextIndex": {
    "name": "example_index_name",
    "definition": {
      "column": "example_text_column",
      "options": {
        "analyzer": {
          "tokenizer": {
            "name": "standard",
            "args": {}
          },
          "filters": [
            {
              "name": "lowercase"
            },
            {
              "name": "stop"
            },
            {
              "name": "porterstem"
            },
            {
              "name": "asciifolding"
            }
          ],
          "charFilters": []
        }
      }
    }
  }
}'

Create a text index only if the index does not exist

Use this option to silently do nothing if a text index with the specified name already exists.

This option only checks index names. It does not check index definitions.

  • Python

  • TypeScript

  • Java

  • curl

from astrapy import DataAPIClient

# Get an existing table
client = DataAPIClient("APPLICATION_TOKEN")
database = client.get_database("API_ENDPOINT")
table = database.get_table("TABLE_NAME")

# Index a column
table.create_text_index(
    "example_index_name",
    column="example_text_column",
    if_not_exists=True,
)
import { DataAPIClient } from "@datastax/astra-db-ts";

// Get an existing table
const client = new DataAPIClient("APPLICATION_TOKEN");
const database = client.db("API_ENDPOINT");
const table = database.table("TABLE_NAME");

// Index a column
(async function () {
  await table.createTextIndex("example_index_name", "example_text_column", {
    ifNotExists: true,
  });
})();
import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.tables.Table;
import com.datastax.astra.client.tables.commands.options.CreateTextIndexOptions;
import com.datastax.astra.client.tables.definition.indexes.TableTextIndexDefinition;
import com.datastax.astra.client.tables.definition.rows.Row;

public class Example {

  public static void main(String[] args) {
    // Get an existing table
    Table<Row> table =
        new DataAPIClient("APPLICATION_TOKEN")
            .getDatabase("API_ENDPOINT")
            .getTable("TABLE_NAME");

    // Index a column
    CreateTextIndexOptions options = new CreateTextIndexOptions().ifNotExists(true);
    TableTextIndexDefinition definition =
        new TableTextIndexDefinition().column("example_text_column");
    table.createTextIndex("example_index_name", definition, options);
  }
}
curl -sS -L -X POST "API_ENDPOINT/api/json/v1/KEYSPACE_NAME/TABLE_NAME" \
  --header "Token: APPLICATION_TOKEN" \
  --header "Content-Type: application/json" \
  --data '{
  "createTextIndex": {
    "name": "example_index_name",
    "definition": {
      "column": "example_text_column"
    },
    "options": {
      "ifNotExists": true
    }
  }
}'

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.

Was this helpful?

Give Feedback

How can we improve the documentation?

© 2025 DataStax, an IBM Company | Privacy policy | Terms of use | Manage Privacy Choices

Apache, Apache Cassandra, Cassandra, Apache Tomcat, Tomcat, Apache Lucene, Apache Solr, Apache Hadoop, Hadoop, Apache Pulsar, Pulsar, Apache Spark, Spark, Apache TinkerPop, TinkerPop, Apache Kafka and Kafka are either registered trademarks or trademarks of the Apache Software Foundation or its subsidiaries in Canada, the United States and/or other countries. Kubernetes is the registered trademark of the Linux Foundation.

General Inquiries: +1 (650) 389-6000, info@datastax.com