Filter operators for tables (Go)

Many Data API commands, like Find rows (Go), accept a filter parameter to determine which rows to return or update. The filter parameter uses one or more filter operators.

You can use filter operators on all supported types except vector. For information about vector search on tables, see Sort clauses for tables (Go).

Operators

You can use the following operators in a filter. All operators are case-sensitive.

Equal (default)

The $eq operator matches rows where the specified column’s value is equal to the specified value.

You can’t use this operator on a column that is associated with a text index.

This is the default when you don’t specify an operator and the column has a regular index or is not indexed.

$eq is not supported for map, list, or set columns.

This is the only filter operator allowed in updateOne and deleteOne.

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/datastax/astra-db-go/v2/astra"
	"github.com/datastax/astra-db-go/v2/astra/filter"
	"github.com/datastax/astra-db-go/v2/astra/options"
)

func main() {
	ctx := context.Background()

	// Get an existing table
	client := astra.NewClient(
		options.API().SetEnvironment(options.EnvironmentHCD),
	)

	database := client.Database(
		"API_ENDPOINT",
		options.API().
			SetUsernamePasswordTokenProvider(
				"USERNAME",
				"PASSWORD",
			).
			SetKeyspace("KEYSPACE_NAME"),
	)

	table := database.Table("TABLE_NAME")

	// Find a row
	var result astra.Row
	err := table.FindOne(
		ctx,
		filter.Eq("number_of_pages", 714),
	).Decode(&result)

	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(result.ToMap())
}

Not equal

The $ne operator matches rows where the specified column’s value is not equal to the specified value.

You can’t use this operator on a column that is associated with a text index.

$ne is not supported for map, list, or set columns.

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/datastax/astra-db-go/v2/astra"
	"github.com/datastax/astra-db-go/v2/astra/filter"
	"github.com/datastax/astra-db-go/v2/astra/options"
)

func main() {
	ctx := context.Background()

	// Get an existing table
	client := astra.NewClient(
		options.API().SetEnvironment(options.EnvironmentHCD),
	)

	database := client.Database(
		"API_ENDPOINT",
		options.API().
			SetUsernamePasswordTokenProvider(
				"USERNAME",
				"PASSWORD",
			).
			SetKeyspace("KEYSPACE_NAME"),
	)

	table := database.Table("TABLE_NAME")

	// Find a row
	var result astra.Row
	err := table.FindOne(
		ctx,
		filter.Ne("number_of_pages", 300),
	).Decode(&result)

	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(result.ToMap())
}

Greater than

The $gt operator matches rows where the specified column’s value is greater than the specified value.

You can’t use this operator on a column that is associated with a text index.

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/datastax/astra-db-go/v2/astra"
	"github.com/datastax/astra-db-go/v2/astra/filter"
	"github.com/datastax/astra-db-go/v2/astra/options"
)

func main() {
	ctx := context.Background()

	// Get an existing table
	client := astra.NewClient(
		options.API().SetEnvironment(options.EnvironmentHCD),
	)

	database := client.Database(
		"API_ENDPOINT",
		options.API().
			SetUsernamePasswordTokenProvider(
				"USERNAME",
				"PASSWORD",
			).
			SetKeyspace("KEYSPACE_NAME"),
	)

	table := database.Table("TABLE_NAME")

	// Find a row
	var result astra.Row
	err := table.FindOne(
		ctx,
		filter.Gt("number_of_pages", 300),
	).Decode(&result)

	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(result.ToMap())
}

Greater than or equal

The $gte operator matches rows where the specified column’s value is greater than or equal to the specified value.

You can’t use this operator on a column that is associated with a text index.

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/datastax/astra-db-go/v2/astra"
	"github.com/datastax/astra-db-go/v2/astra/filter"
	"github.com/datastax/astra-db-go/v2/astra/options"
)

func main() {
	ctx := context.Background()

	// Get an existing table
	client := astra.NewClient(
		options.API().SetEnvironment(options.EnvironmentHCD),
	)

	database := client.Database(
		"API_ENDPOINT",
		options.API().
			SetUsernamePasswordTokenProvider(
				"USERNAME",
				"PASSWORD",
			).
			SetKeyspace("KEYSPACE_NAME"),
	)

	table := database.Table("TABLE_NAME")

	// Find a row
	var result astra.Row
	err := table.FindOne(
		ctx,
		filter.Gte("number_of_pages", 300),
	).Decode(&result)

	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(result.ToMap())
}

Less than

The $lt operator matches rows where the specified column’s value is less than the specified value.

You can’t use this operator on a column that is associated with a text index.

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/datastax/astra-db-go/v2/astra"
	"github.com/datastax/astra-db-go/v2/astra/filter"
	"github.com/datastax/astra-db-go/v2/astra/options"
)

func main() {
	ctx := context.Background()

	// Get an existing table
	client := astra.NewClient(
		options.API().SetEnvironment(options.EnvironmentHCD),
	)

	database := client.Database(
		"API_ENDPOINT",
		options.API().
			SetUsernamePasswordTokenProvider(
				"USERNAME",
				"PASSWORD",
			).
			SetKeyspace("KEYSPACE_NAME"),
	)

	table := database.Table("TABLE_NAME")

	// Find a row
	var result astra.Row
	err := table.FindOne(
		ctx,
		filter.Lt("number_of_pages", 300),
	).Decode(&result)

	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(result.ToMap())
}

Less than or equal

The $lte operator matches rows where the specified column’s value is less than or equal to the specified value.

You can’t use this operator on a column that is associated with a text index.

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/datastax/astra-db-go/v2/astra"
	"github.com/datastax/astra-db-go/v2/astra/filter"
	"github.com/datastax/astra-db-go/v2/astra/options"
)

func main() {
	ctx := context.Background()

	// Get an existing table
	client := astra.NewClient(
		options.API().SetEnvironment(options.EnvironmentHCD),
	)

	database := client.Database(
		"API_ENDPOINT",
		options.API().
			SetUsernamePasswordTokenProvider(
				"USERNAME",
				"PASSWORD",
			).
			SetKeyspace("KEYSPACE_NAME"),
	)

	table := database.Table("TABLE_NAME")

	// Find a row
	var result astra.Row
	err := table.FindOne(
		ctx,
		filter.Lte("number_of_pages", 300),
	).Decode(&result)

	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(result.ToMap())
}

In

The behavior of $in depends on the type of column it is applied to:

  • List and set columns: The $in operator matches rows where the filtered column contains any of the specified values.

  • Map columns: The $in operator matches rows where the filtered column contains any of the specified key-value pairs. Each key-value pair is specified as an array.

    To match specific keys or specific values, rather than key-value pairs, use the $keys or $values operator.

  • Other column types: The $in operator matches rows where the filtered column has a value equal to any of the specified values.

For a non-map column, specify the values as an array:

You can’t use this operator on a column that is associated with a text index.

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/datastax/astra-db-go/v2/astra"
	"github.com/datastax/astra-db-go/v2/astra/filter"
	"github.com/datastax/astra-db-go/v2/astra/options"
)

func main() {
	ctx := context.Background()

	// Get an existing table
	client := astra.NewClient(
		options.API().SetEnvironment(options.EnvironmentHCD),
	)

	database := client.Database(
		"API_ENDPOINT",
		options.API().
			SetUsernamePasswordTokenProvider(
				"USERNAME",
				"PASSWORD",
			).
			SetKeyspace("KEYSPACE_NAME"),
	)

	table := database.Table("TABLE_NAME")

	// Find a row
	var result astra.Row
	err := table.FindOne(
		ctx,
		filter.In("author", "Sara Jones", "Jennifer Ray"),
	).Decode(&result)

	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(result.ToMap())
}

For map columns, specify the values as an array of key-value pairs, where each key-value pair is an array:

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/datastax/astra-db-go/v2/astra"
	"github.com/datastax/astra-db-go/v2/astra/filter"
	"github.com/datastax/astra-db-go/v2/astra/options"
)

func main() {
	ctx := context.Background()

	// Get an existing table
	client := astra.NewClient(
		options.API().SetEnvironment(options.EnvironmentHCD),
	)

	database := client.Database(
		"API_ENDPOINT",
		options.API().
			SetUsernamePasswordTokenProvider(
				"USERNAME",
				"PASSWORD",
			).
			SetKeyspace("KEYSPACE_NAME"),
	)

	table := database.Table("TABLE_NAME")

	// Find a row
	var result astra.Row
	err := table.FindOne(
		ctx,
		filter.In(
			"metadata",
			[]string{"language", "French"},
			[]string{"edition", "Illustrated Edition"},
		),
	).Decode(&result)

	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(result.ToMap())
}

Not in

The behavior of $nin depends on the type of column it is applied to:

  • List and set columns: The $nin operator matches rows where the column doesn’t contain any of the specified values.

  • Map columns: The $nin operator matches rows where the column doesn’t contain any of the specified key-value pairs. Each key-value pair is specified as an array.

    To match specific keys or specific values, rather than key-value pairs, use the $keys or $values operator.

  • Other column types: The $nin operator matches rows that don’t contain any of the specified values.

For a non-map column, specify the values as an array:

You can’t use this operator on a column that is associated with a text index.

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/datastax/astra-db-go/v2/astra"
	"github.com/datastax/astra-db-go/v2/astra/filter"
	"github.com/datastax/astra-db-go/v2/astra/options"
)

func main() {
	ctx := context.Background()

	// Get an existing table
	client := astra.NewClient(
		options.API().SetEnvironment(options.EnvironmentHCD),
	)

	database := client.Database(
		"API_ENDPOINT",
		options.API().
			SetUsernamePasswordTokenProvider(
				"USERNAME",
				"PASSWORD",
			).
			SetKeyspace("KEYSPACE_NAME"),
	)

	table := database.Table("TABLE_NAME")

	// Find a row
	var result astra.Row
	err := table.FindOne(
		ctx,
		filter.Nin("author", "Sara Jones", "Jennifer Ray"),
	).Decode(&result)

	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(result.ToMap())
}

For map columns, specify the values as an array of key-value pairs, where each key-value pair is an array:

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/datastax/astra-db-go/v2/astra"
	"github.com/datastax/astra-db-go/v2/astra/filter"
	"github.com/datastax/astra-db-go/v2/astra/options"
)

func main() {
	ctx := context.Background()

	// Get an existing table
	client := astra.NewClient(
		options.API().SetEnvironment(options.EnvironmentHCD),
	)

	database := client.Database(
		"API_ENDPOINT",
		options.API().
			SetUsernamePasswordTokenProvider(
				"USERNAME",
				"PASSWORD",
			).
			SetKeyspace("KEYSPACE_NAME"),
	)

	table := database.Table("TABLE_NAME")

	// Find a row
	var result astra.Row
	err := table.FindOne(
		ctx,
		filter.Nin(
			"metadata",
			[]string{"language", "French"},
			[]string{"edition", "Illustrated Edition"},
		),
	).Decode(&result)

	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(result.ToMap())
}

All

The behavior of $all depends on the type of column it is applied to:

  • List and set columns: The $all operator matches rows where the column contains all of the specified values.

  • Map columns: The $all operator matches rows where the column contains all of the specified key-value pairs. Each key-value pair is specified as an array.

    To match specific keys or specific values, rather than key-value pairs, use the $keys or $values operator.

The $all operator is only supported for map, list, and set columns.

For a list or set column, specify the values as an array:

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/datastax/astra-db-go/v2/astra"
	"github.com/datastax/astra-db-go/v2/astra/filter"
	"github.com/datastax/astra-db-go/v2/astra/options"
)

func main() {
	ctx := context.Background()

	// Get an existing table
	client := astra.NewClient(
		options.API().SetEnvironment(options.EnvironmentHCD),
	)

	database := client.Database(
		"API_ENDPOINT",
		options.API().
			SetUsernamePasswordTokenProvider(
				"USERNAME",
				"PASSWORD",
			).
			SetKeyspace("KEYSPACE_NAME"),
	)

	table := database.Table("TABLE_NAME")

	// Find a row
	var result astra.Row
	err := table.FindOne(
		ctx,
		filter.All("genres", "Fantasy", "Romance"),
	).Decode(&result)

	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(result.ToMap())
}

For map columns, specify the values as an array of key-value pairs, where each key-value pair is an array:

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/datastax/astra-db-go/v2/astra"
	"github.com/datastax/astra-db-go/v2/astra/filter"
	"github.com/datastax/astra-db-go/v2/astra/options"
)

func main() {
	ctx := context.Background()

	// Get an existing table
	client := astra.NewClient(
		options.API().SetEnvironment(options.EnvironmentHCD),
	)

	database := client.Database(
		"API_ENDPOINT",
		options.API().
			SetUsernamePasswordTokenProvider(
				"USERNAME",
				"PASSWORD",
			).
			SetKeyspace("KEYSPACE_NAME"),
	)

	table := database.Table("TABLE_NAME")

	// Find a row
	var result astra.Row
	err := table.FindOne(
		ctx,
		filter.All("metadata",
			[]string{"language", "Italian"},
			[]string{"language", "Italian"}),
	).Decode(&result)

	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(result.ToMap())
}

Keys

Only supported for map columns.

In conjunction with $in, the $keys operator matches rows where the map column contains any of the specified keys.

In conjunction with $all, the $keys operator matches rows where the map column contains all of the specified keys.

In conjunction with $nin, the $keys operator matches rows where the map column doesn’t contain any of the specified keys.

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/datastax/astra-db-go/v2/astra"
	"github.com/datastax/astra-db-go/v2/astra/filter"
	"github.com/datastax/astra-db-go/v2/astra/options"
)

func main() {
	ctx := context.Background()

	// Get an existing table
	client := astra.NewClient(
		options.API().SetEnvironment(options.EnvironmentHCD),
	)

	database := client.Database(
		"API_ENDPOINT",
		options.API().
			SetUsernamePasswordTokenProvider(
				"USERNAME",
				"PASSWORD",
			).
			SetKeyspace("KEYSPACE_NAME"),
	)

	table := database.Table("TABLE_NAME")

	// Find a row
	var result astra.Row
	err := table.FindOne(
		ctx,
		filter.Table.Keys(filter.In("metadata", "language", "edition")),
	).Decode(&result)

	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(result.ToMap())
}

Values

Only supported for map columns.

In conjunction with $in, the $values operator matches rows where the map column contains any of the specified values.

In conjunction with $all, the $values operator matches rows where the map column contains all of the specified values.

In conjunction with $nin, the $values operator matches rows where the map column doesn’t contain any of the specified values.

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/datastax/astra-db-go/v2/astra"
	"github.com/datastax/astra-db-go/v2/astra/filter"
	"github.com/datastax/astra-db-go/v2/astra/options"
)

func main() {
	ctx := context.Background()

	// Get an existing table
	client := astra.NewClient(
		options.API().SetEnvironment(options.EnvironmentHCD),
	)

	database := client.Database(
		"API_ENDPOINT",
		options.API().
			SetUsernamePasswordTokenProvider(
				"USERNAME",
				"PASSWORD",
			).
			SetKeyspace("KEYSPACE_NAME"),
	)

	table := database.Table("TABLE_NAME")

	// Find a row
	var result astra.Row
	err := table.FindOne(
		ctx,
		filter.Table.Values(
			filter.In("metadata", "French", "Illustrated Edition"),
		),
	).Decode(&result)

	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(result.ToMap())
}

Match

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.

The $match operator matches rows where the specified column’s value is a lexicographical match to the specified string of space-separated keywords or terms.

You can only use the $match operator on a column that is associated with a text index. This is the only filter operator that you can use on columns associated with a text index.

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/datastax/astra-db-go/v2/astra"
	"github.com/datastax/astra-db-go/v2/astra/filter"
	"github.com/datastax/astra-db-go/v2/astra/options"
)

func main() {
	ctx := context.Background()

	// Get an existing table
	client := astra.NewClient(
		options.API().SetEnvironment(options.EnvironmentHCD),
	)

	database := client.Database(
		"API_ENDPOINT",
		options.API().
			SetUsernamePasswordTokenProvider(
				"USERNAME",
				"PASSWORD",
			).
			SetKeyspace("KEYSPACE_NAME"),
	)

	table := database.Table("TABLE_NAME")

	// Find a row
	var result astra.Row
	err := table.FindOne(
		ctx,
		filter.Table.LexicalMatch(
			"summary",
			"futuristic laboratory discovery",
		),
	).Decode(&result)

	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(result.ToMap())
}

Combine operators (And, Or)

The $and operator joins clauses with a logical AND. Only rows that match the conditions of all clauses are returned.

The $or operator joins clauses with a logical OR. Rows that match the condition of any of the clauses are returned.

You can use $and and $or separately or together. If you want to match multiple flexible conditions, use $and and $or together in the same filter:

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/datastax/astra-db-go/v2/astra"
	"github.com/datastax/astra-db-go/v2/astra/filter"
	"github.com/datastax/astra-db-go/v2/astra/options"
)

func main() {
	ctx := context.Background()

	// Get an existing table
	client := astra.NewClient(
		options.API().SetEnvironment(options.EnvironmentHCD),
	)

	database := client.Database(
		"API_ENDPOINT",
		options.API().
			SetUsernamePasswordTokenProvider(
				"USERNAME",
				"PASSWORD",
			).
			SetKeyspace("KEYSPACE_NAME"),
	)

	table := database.Table("TABLE_NAME")

	// Find a row
	var result astra.Row
	err := table.FindOne(
		ctx,
		filter.And(
			filter.Or(
				filter.Eq("is_checked_out", false),
				filter.Lt("number_of_pages", 300),
			),
			filter.Or(
				filter.Lt("rating", 4.3),
				filter.Gte("publication_year", 2002),
			),
		),
	).Decode(&result)

	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(result.ToMap())
}

To filter on a range of values, use $and with $lt/$lte and $gt/$gte:

package main

import (
	"context"
	"fmt"
	"log"

	"github.com/datastax/astra-db-go/v2/astra"
	"github.com/datastax/astra-db-go/v2/astra/filter"
	"github.com/datastax/astra-db-go/v2/astra/options"
)

func main() {
	ctx := context.Background()

	// Get an existing table
	client := astra.NewClient(
		options.API().SetEnvironment(options.EnvironmentHCD),
	)

	database := client.Database(
		"API_ENDPOINT",
		options.API().
			SetUsernamePasswordTokenProvider(
				"USERNAME",
				"PASSWORD",
			).
			SetKeyspace("KEYSPACE_NAME"),
	)

	table := database.Table("TABLE_NAME")

	// Find a row
	var result astra.Row
	err := table.FindOne(
		ctx,
		filter.And(
			filter.Lt("number_of_pages", 300),
			filter.Gte("number_of_pages", 200),
		),
	).Decode(&result)

	if err != nil {
		log.Fatal(err)
	}

	fmt.Println(result.ToMap())
}

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