Create a text index (C#)

Lexicographical matching is currently in public preview. Development is ongoing, and the features and functionality are subject to change. Hyper-Converged Database (HCD), 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 (C#) 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

Creates a text index for the specified column.

Does not return anything.

Parameters

Use the CreateTextIndexAsync method, which belongs to the Table class. You can also use CreateTextIndex, which is the synchronous version of the method.

Method signature
public Task CreateTextIndexAsync(
  string indexName,
  string columnName,
  CreateTextIndexOptions options = null
);
public Task CreateTextIndexAsync<TColumn>(
  string indexName,
  Expression<Func<T, TColumn>> column,
  CreateTextIndexOptions options = null
);
public Task CreateTextIndexAsync(
  string indexName,
  string columnName,
  TableTextIndexDefinition indexDefinition,
  CreateTextIndexOptions options = null
);
public Task CreateTextIndexAsync<TColumn>(
  string indexName,
  Expression<Func<T, TColumn>> column,
  TableTextIndexDefinition indexDefinition,
  CreateTextIndexOptions options = null
);
Name Type Summary

indexName

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

columnName

string

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

The column must be a text or ascii column.

indexDefinition

TableTextIndexDefinition

Definition of the index to create.

You can use Builders.TableIndex.Text() methods to create the TableTextIndexDefinition. See Parameters of Builders.TableIndex.Text() for creating TableTextIndexDefinition for more details.

options

CreateTextIndexOptions

Optional. Options for this operation. For more information and examples for general options such as timeout, see Customize API interaction. For options specific to this method, see Method-specific properties of the CreateTextIndexOptions class.

Parameters of Builders.TableIndex.Text() for creating TableTextIndexDefinition
Name Type Summary

analyzer

string | object | TextAnalyzer

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

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

JSON objects must follow the specifications in Configure and use SAI text analyzers with CQL.

See the examples for usage.

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

analyzerOptions

AnalyzerOptions

Optional. An alternative to the analyzer parameter. Custom analyzer options describing an analyzer configuration.

The AnalyzerOptions object must follow the specifications in Configure and use SAI text analyzers with CQL.

See the examples for usage.

Method-specific properties of the CreateTextIndexOptions class
Name Type Summary

IfNotExists

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

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.

using DataStax.AstraDB.DataApi;
using DataStax.AstraDB.DataApi.Core;

namespace Examples;

public class Program
{
  static async Task Main()
  {
    // Get an existing table
    var client = new DataAPIClient(
      new CommandOptions() { Destination = DataAPIDestination.HCD }
    );

    var database = client.GetDatabase(
      "API_ENDPOINT",
      DataAPIClient.UsernamePasswordTokenProvider(
        "USERNAME",
        "PASSWORD"
      ),
      "KEYSPACE_NAME"
    );

    var table = database.GetTable("TABLE_NAME");

    // Index a column
    await table.CreateTextIndexAsync(
      "INDEX_NAME",
      "TEXT_COLUMN_NAME"
    );
  }
}

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.

using DataStax.AstraDB.DataApi;
using DataStax.AstraDB.DataApi.Core;

namespace Examples;

public class Program
{
  static async Task Main()
  {
    // Get an existing table
    var client = new DataAPIClient(
      new CommandOptions() { Destination = DataAPIDestination.HCD }
    );

    var database = client.GetDatabase(
      "API_ENDPOINT",
      DataAPIClient.UsernamePasswordTokenProvider(
        "USERNAME",
        "PASSWORD"
      ),
      "KEYSPACE_NAME"
    );

    var table = database.GetTable("TABLE_NAME");

    // Index a column
    await table.CreateTextIndexAsync(
      "INDEX_NAME",
      "TEXT_COLUMN_NAME",
      Builders.TableIndex.Text("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 Configure and use SAI text analyzers with CQL.

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.

using DataStax.AstraDB.DataApi;
using DataStax.AstraDB.DataApi.Core;

namespace Examples;

public class Program
{
  static async Task Main()
  {
    // Get an existing table
    var client = new DataAPIClient(
      new CommandOptions() { Destination = DataAPIDestination.HCD }
    );

    var database = client.GetDatabase(
      "API_ENDPOINT",
      DataAPIClient.UsernamePasswordTokenProvider(
        "USERNAME",
        "PASSWORD"
      ),
      "KEYSPACE_NAME"
    );

    var table = database.GetTable("TABLE_NAME");

    // Index a column
    await table.CreateTextIndexAsync(
      "INDEX_NAME",
      "TEXT_COLUMN_NAME",
      Builders.TableIndex.Text(
        new AnalyzerOptions
        {
          Tokenizer = new TokenizerOptions
          {
            Name = "standard",
            Arguments = new Dictionary<string, object>(),
          },
          Filters = { "lowercase", "stop", "porterstem", "asciifolding" },
          CharacterFilters = new List<string>(),
        }
      )
    );
  }
}

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.

using DataStax.AstraDB.DataApi;
using DataStax.AstraDB.DataApi.Core;
using DataStax.AstraDB.DataApi.Tables;

namespace Examples;

public class Program
{
  static async Task Main()
  {
    // Get an existing table
    var client = new DataAPIClient(
      new CommandOptions() { Destination = DataAPIDestination.HCD }
    );

    var database = client.GetDatabase(
      "API_ENDPOINT",
      DataAPIClient.UsernamePasswordTokenProvider(
        "USERNAME",
        "PASSWORD"
      ),
      "KEYSPACE_NAME"
    );

    var table = database.GetTable("TABLE_NAME");

    // Index a column
    await table.CreateTextIndexAsync(
      "INDEX_NAME",
      "TEXT_COLUMN_NAME",
      new CreateTextIndexOptions() { IfNotExists = true }
    );
  }
}

Client reference

For more information, see the client reference.

Was this helpful?

Give Feedback

How can we improve the documentation?

© Copyright IBM Corporation 2026 | 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: Contact IBM