Filter operators for tables
Many Data API commands, like Find rows, 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.
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 the 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.
-
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")
# Find a row
result = table.find_one({"number_of_pages": {"$eq": 300}})
print(result)
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");
// Find a row
(async function () {
const result = await table.findOne({ number_of_pages: { $eq: 300 } });
console.log(result);
})();
import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.core.query.Filter;
import com.datastax.astra.client.core.query.Filters;
import com.datastax.astra.client.tables.Table;
import com.datastax.astra.client.tables.definition.rows.Row;
import java.util.Optional;
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");
// Find a row
Filter filter = Filters.eq("number_of_pages", 300);
Optional<Row> result = table.findOne(filter);
System.out.println(result);
}
}
curl -sS -L -X POST "API_ENDPOINT/api/json/v1/KEYSPACE_NAME/TABLE_NAME" \
--header "Token: APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"findOne": {
"filter": {"number_of_pages": {"$eq": 300}}
}
}'
Not equal
The $ne
operator matches rows where the specified column’s value is not equal to the specified value.
You can’t use the this operator on a column that is associated with a text index.
$ne
is not supported for map, list, or set columns.
-
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")
# Find a row
result = table.find_one({"number_of_pages": {"$ne": 300}})
print(result)
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");
// Find a row
(async function () {
const result = await table.findOne({ number_of_pages: { $ne: 300 } });
console.log(result);
})();
import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.core.query.Filter;
import com.datastax.astra.client.core.query.Filters;
import com.datastax.astra.client.tables.Table;
import com.datastax.astra.client.tables.definition.rows.Row;
import java.util.Optional;
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");
// Find a row
Filter filter = Filters.ne("number_of_pages", 300);
Optional<Row> result = table.findOne(filter);
System.out.println(result);
}
}
curl -sS -L -X POST "API_ENDPOINT/api/json/v1/KEYSPACE_NAME/TABLE_NAME" \
--header "Token: APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"findOne": {
"filter": {"number_of_pages": {"$ne": 300}}
}
}'
Greater than
The $gt
operator matches rows where the specified column’s value is greater than the specified value.
You can’t use the this operator on a column that is associated with a text index.
-
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")
# Find a row
result = table.find_one({"number_of_pages": {"$gt": 300}})
print(result)
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");
// Find a row
(async function () {
const result = await table.findOne({ number_of_pages: { $gt: 300 } });
console.log(result);
})();
import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.core.query.Filter;
import com.datastax.astra.client.core.query.Filters;
import com.datastax.astra.client.tables.Table;
import com.datastax.astra.client.tables.definition.rows.Row;
import java.util.Optional;
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");
// Find a row
Filter filter = Filters.gt("number_of_pages", 300);
Optional<Row> result = table.findOne(filter);
System.out.println(result);
}
}
curl -sS -L -X POST "API_ENDPOINT/api/json/v1/KEYSPACE_NAME/TABLE_NAME" \
--header "Token: APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"findOne": {
"filter": {"number_of_pages": {"$gt": 300}}
}
}'
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 the this operator on a column that is associated with a text index.
-
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")
# Find a row
result = table.find_one({"number_of_pages": {"$gte": 300}})
print(result)
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");
// Find a row
(async function () {
const result = await table.findOne({ number_of_pages: { $gte: 300 } });
console.log(result);
})();
import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.core.query.Filter;
import com.datastax.astra.client.core.query.Filters;
import com.datastax.astra.client.tables.Table;
import com.datastax.astra.client.tables.definition.rows.Row;
import java.util.Optional;
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");
// Find a row
Filter filter = Filters.gte("number_of_pages", 300);
Optional<Row> result = table.findOne(filter);
System.out.println(result);
}
}
curl -sS -L -X POST "API_ENDPOINT/api/json/v1/KEYSPACE_NAME/TABLE_NAME" \
--header "Token: APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"findOne": {
"filter": {"number_of_pages": {"$gte": 300}}
}
}'
Less than
The $lt
operator matches rows where the specified column’s value is less than the specified value.
You can’t use the this operator on a column that is associated with a text index.
-
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")
# Find a row
result = table.find_one({"number_of_pages": {"$lt": 300}})
print(result)
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");
// Find a row
(async function () {
const result = await table.findOne({ number_of_pages: { $lt: 300 } });
console.log(result);
})();
import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.core.query.Filter;
import com.datastax.astra.client.core.query.Filters;
import com.datastax.astra.client.tables.Table;
import com.datastax.astra.client.tables.definition.rows.Row;
import java.util.Optional;
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");
// Find a row
Filter filter = Filters.lt("number_of_pages", 300);
Optional<Row> result = table.findOne(filter);
System.out.println(result);
}
}
curl -sS -L -X POST "API_ENDPOINT/api/json/v1/KEYSPACE_NAME/TABLE_NAME" \
--header "Token: APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"findOne": {
"filter": {"number_of_pages": {"$lt": 300}}
}
}'
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 the this operator on a column that is associated with a text index.
-
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")
# Find a row
result = table.find_one({"number_of_pages": {"$lte": 300}})
print(result)
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");
// Find a row
(async function () {
const result = await table.findOne({ number_of_pages: { $lte: 300 } });
console.log(result);
})();
import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.core.query.Filter;
import com.datastax.astra.client.core.query.Filters;
import com.datastax.astra.client.tables.Table;
import com.datastax.astra.client.tables.definition.rows.Row;
import java.util.Optional;
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");
// Find a row
Filter filter = Filters.lte("number_of_pages", 300);
Optional<Row> result = table.findOne(filter);
System.out.println(result);
}
}
curl -sS -L -X POST "API_ENDPOINT/api/json/v1/KEYSPACE_NAME/TABLE_NAME" \
--header "Token: APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"findOne": {
"filter": {"number_of_pages": {"$lte": 300}}
}
}'
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. -
Other column types: The
$in
operator matches rows where the filtered column contains any of the specified values.
For a non-map column, specify the values as an array:
You can’t use the this operator on a column that is associated with a text index.
-
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")
# Find a row
result = table.find_one({"author": {"$in": ["Sara Jones", "Jennifer Ray"]}})
print(result)
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");
// Find a row
(async function () {
const result = await table.findOne({
author: { $in: ["Sara Jones", "Jennifer Ray"] },
});
console.log(result);
})();
import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.core.query.Filter;
import com.datastax.astra.client.core.query.Filters;
import com.datastax.astra.client.tables.Table;
import com.datastax.astra.client.tables.definition.rows.Row;
import java.util.Optional;
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");
// Find a row
Filter filter = Filters.in("author", "Sara Jones", "Jennifer Ray");
Optional<Row> result = table.findOne(filter);
System.out.println(result);
}
}
curl -sS -L -X POST "API_ENDPOINT/api/json/v1/KEYSPACE_NAME/TABLE_NAME" \
--header "Token: APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"findOne": {
"filter": {"author": {"$in": ["Sara Jones", "Jennifer Ray"]}}
}
}'
For map columns, specify the values as an array of key-value pairs, where each key-value pair is an array:
-
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")
# Find a row
result = table.find_one(
{"metadata": {"$in": [["language", "French"], ["edition", "Illustrated Edition"]]}}
)
print(result)
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");
// Find a row
(async function () {
const result = await table.findOne({
metadata: {
$in: [
["language", "French"],
["edition", "Illustrated Edition"],
],
},
});
console.log(result);
})();
import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.core.query.Filter;
import com.datastax.astra.client.core.query.Filters;
import com.datastax.astra.client.tables.Table;
import com.datastax.astra.client.tables.definition.rows.Row;
import java.util.List;
import java.util.Optional;
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");
// Find a row
Filter filter =
Filters.in(
"metadata", List.of("language", "French"), List.of("edition", "Illustrated Edition"));
Optional<Row> result = table.findOne(filter);
System.out.println(result);
}
}
curl -sS -L -X POST "API_ENDPOINT/api/json/v1/KEYSPACE_NAME/TABLE_NAME" \
--header "Token: APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"findOne": {
"filter": {"metadata": {"$in": [["language", "French"], ["edition", "Illustrated Edition"]]}}
}
}'
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. -
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 the this operator on a column that is associated with a text index.
-
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")
# Find a row
result = table.find_one({"author": {"$nin": ["Sara Jones", "Jennifer Ray"]}})
print(result)
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");
// Find a row
(async function () {
const result = await table.findOne({
author: { $nin: ["Sara Jones", "Jennifer Ray"] },
});
console.log(result);
})();
import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.core.query.Filter;
import com.datastax.astra.client.core.query.Filters;
import com.datastax.astra.client.tables.Table;
import com.datastax.astra.client.tables.definition.rows.Row;
import java.util.Optional;
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");
// Find a row
Filter filter = Filters.nin("author", "Sara Jones", "Jennifer Ray");
Optional<Row> result = table.findOne(filter);
System.out.println(result);
}
}
curl -sS -L -X POST "API_ENDPOINT/api/json/v1/KEYSPACE_NAME/TABLE_NAME" \
--header "Token: APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"findOne": {
"filter": {"author": {"$nin": ["Sara Jones", "Jennifer Ray"]}}
}
}'
For map columns, specify the values as an array of key-value pairs, where each key-value pair is an array:
-
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")
# Find a row
result = table.find_one(
{"metadata": {"$nin": [["language", "French"], ["edition", "Illustrated Edition"]]}}
)
print(result)
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");
// Find a row
(async function () {
const result = await table.findOne({
metadata: {
$nin: [
["language", "French"],
["edition", "Illustrated Edition"],
],
},
});
console.log(result);
})();
import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.core.query.Filter;
import com.datastax.astra.client.core.query.Filters;
import com.datastax.astra.client.tables.Table;
import com.datastax.astra.client.tables.definition.rows.Row;
import java.util.List;
import java.util.Optional;
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");
// Find a row
Filter filter =
Filters.nin(
"metadata", List.of("language", "French"), List.of("edition", "Illustrated Edition"));
Optional<Row> result = table.findOne(filter);
System.out.println(result);
}
}
curl -sS -L -X POST "API_ENDPOINT/api/json/v1/KEYSPACE_NAME/TABLE_NAME" \
--header "Token: APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"findOne": {
"filter": {"metadata": {"$nin": [["language", "French"], ["edition", "Illustrated Edition"]]}}
}
}'
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.
The $all
operator is only supported for map, list, and set columns.
For a list or set column, specify the values as an array:
-
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")
# Find a row
result = table.find_one({"genres": {"$all": ["Fantasy", "Romance"]}})
print(result)
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");
// Find a row
(async function () {
const result = await table.findOne({
genres: { $all: ["Fantasy", "Romance"] },
});
console.log(result);
})();
import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.core.query.Filter;
import com.datastax.astra.client.core.query.Filters;
import com.datastax.astra.client.tables.Table;
import com.datastax.astra.client.tables.definition.rows.Row;
import java.util.Optional;
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");
// Find a row
Filter filter = Filters.all("genres", "Fantasy", "Romance");
Optional<Row> result = table.findOne(filter);
System.out.println(result);
}
}
curl -sS -L -X POST "API_ENDPOINT/api/json/v1/KEYSPACE_NAME/TABLE_NAME" \
--header "Token: APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"findOne": {
"filter": {"genres": {"$all": ["Fantasy", "Romance"]}}
}
}'
For map columns, specify the values as an array of key-value pairs, where each key-value pair is an array:
-
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")
# Find a row
result = table.find_one(
{
"metadata": {
"$all": [["language", "Italian"], ["edition", "Illustrated Edition"]]
}
}
)
print(result)
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");
// Find a row
(async function () {
const result = await table.findOne({
metadata: {
$all: [
["language", "Italian"],
["edition", "Illustrated Edition"],
],
},
});
console.log(result);
})();
import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.core.query.Filter;
import com.datastax.astra.client.core.query.Filters;
import com.datastax.astra.client.tables.Table;
import com.datastax.astra.client.tables.definition.rows.Row;
import java.util.List;
import java.util.Optional;
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");
// Find a row
Filter filter =
Filters.all(
"metadata", List.of("language", "Italian"), List.of("edition", "Illustrated Edition"));
Optional<Row> result = table.findOne(filter);
System.out.println(result);
}
}
curl -sS -L -X POST "API_ENDPOINT/api/json/v1/KEYSPACE_NAME/TABLE_NAME" \
--header "Token: APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"findOne": {
"filter": {"metadata": {"$all": [["language", "Italian"], ["edition", "Illustrated Edition"]]}}
}
}'
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.
-
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")
# Find a row
result = table.find_one({"metadata": {"$keys": {"$in": ["language", "edition"]}}})
print(result)
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");
// Find a row
(async function () {
const result = await table.findOne({
metadata: { $keys: { $in: ["language", "edition"] } },
});
console.log(result);
})();
import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.core.query.Filter;
import com.datastax.astra.client.tables.Table;
import com.datastax.astra.client.tables.definition.rows.Row;
import java.util.Arrays;
import java.util.Map;
import java.util.Optional;
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");
// Find a row
Filter filter =
new Filter(
Map.of(
"metadata", Map.of("$keys", Map.of("$in", Arrays.asList("language", "edition")))));
Optional<Row> result = table.findOne(filter);
System.out.println(result);
}
}
curl -sS -L -X POST "API_ENDPOINT/api/json/v1/KEYSPACE_NAME/TABLE_NAME" \
--header "Token: APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"findOne": {
"filter": {
"metadata": {
"$keys": {
"$in": ["language", "edition"]
}
}
}
}
}'
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.
-
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")
# Find a row
result = table.find_one(
{"metadata": {"$values": {"$in": ["French", "Illustrated Edition"]}}}
)
print(result)
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");
// Find a row
(async function () {
const result = await table.findOne({
metadata: { $values: { $in: ["French", "Illustrated Edition"] } },
});
console.log(result);
})();
import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.core.query.Filter;
import com.datastax.astra.client.tables.Table;
import com.datastax.astra.client.tables.definition.rows.Row;
import java.util.Arrays;
import java.util.Map;
import java.util.Optional;
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");
// Find a row
Filter filter =
new Filter(
Map.of(
"metadata",
Map.of("$values", Map.of("$in", Arrays.asList("French", "Illustrated Edition")))));
Optional<Row> result = table.findOne(filter);
System.out.println(result);
}
}
curl -sS -L -X POST "API_ENDPOINT/api/json/v1/KEYSPACE_NAME/TABLE_NAME" \
--header "Token: APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"findOne": {
"filter": {
"metadata": {
"$values": {
"$in": ["French", "Illustrated Edition"]
}
}
}
}
}'
Match
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. |
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.
-
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")
# Find a row
result = table.find_one({"summary": {"$match": "futuristic laboratory discovery"}})
print(result)
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");
// Find a row
(async function () {
const result = await table.findOne({
summary: { $match: "futuristic laboratory discovery" },
});
console.log(result);
})();
import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.core.query.Filter;
import com.datastax.astra.client.core.query.Filters;
import com.datastax.astra.client.tables.Table;
import com.datastax.astra.client.tables.definition.rows.Row;
import java.util.Optional;
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");
// Find a row
Filter filter = Filters.match("summary", "futuristic laboratory discovery");
Optional<Row> result = table.findOne(filter);
System.out.println(result);
}
}
curl -sS -L -X POST "API_ENDPOINT/api/json/v1/KEYSPACE_NAME/TABLE_NAME" \
--header "Token: APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"findOne": {
"filter": {
"summary": {"$match": "futuristic laboratory discovery"}
}
}
}'
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:
-
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")
# Find a row
result = table.find_one(
{
"$and": [
{"$or": [{"is_checked_out": False}, {"number_of_pages": {"$lt": 300}}]},
{
"$or": [
{"author": {"$in": ["Sara Jones", "Jennifer Ray"]}},
{"publication_year": {"$gte": 2002}},
]
},
]
}
)
print(result)
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");
// Find a row
(async function () {
const result = await table.findOne({
$and: [
{
$or: [{ is_checked_out: false }, { number_of_pages: { $lt: 300 } }],
},
{
$or: [
{ genres: { $in: ["Sara Jones", "Jennifer Ray"] } },
{ publication_year: { $gte: 2002 } },
],
},
],
});
console.log(result);
})();
import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.core.query.Filter;
import com.datastax.astra.client.core.query.Filters;
import com.datastax.astra.client.tables.Table;
import com.datastax.astra.client.tables.definition.rows.Row;
import java.util.Optional;
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");
// Find a row
Filter filter =
Filters.and(
Filters.or(Filters.eq("is_checked_out", false), Filters.lt("number_of_pages", 300)),
Filters.or(
Filters.in("author", "Sara Jones", "Jennifer Ray"),
Filters.gte("publication_year", 2002)));
Optional<Row> result = table.findOne(filter);
System.out.println(result);
}
}
curl -sS -L -X POST "API_ENDPOINT/api/json/v1/KEYSPACE_NAME/TABLE_NAME" \
--header "Token: APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"findOne": {
"filter": {
"$and": [
{
"$or": [
{ "is_checked_out": false },
{"number_of_pages": {"$lt": 300}}
]
},
{
"$or": [
{"author": {"$in": ["Sara Jones", "Jennifer Ray"]}},
{"publication_year": {"$gte": 2002}}
]
}
]
}
}
}'
To filter on a range of values, use $and
with $lt
/$lte
and $gt
/$gte
:
-
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")
# Find a row
result = table.find_one(
{
"$and": [
{"number_of_pages": {"$lt": 300}},
{"number_of_pages": {"$gte": 200}},
]
}
)
print(result)
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");
// Find a row
(async function () {
const result = await table.findOne({
$and: [
{ number_of_pages: { $lt: 300 } },
{ number_of_pages: { $gte: 200 } },
],
});
console.log(result);
})();
import com.datastax.astra.client.DataAPIClient;
import com.datastax.astra.client.core.query.Filter;
import com.datastax.astra.client.core.query.Filters;
import com.datastax.astra.client.tables.Table;
import com.datastax.astra.client.tables.definition.rows.Row;
import java.util.Optional;
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");
// Find a row
Filter filter =
Filters.and(Filters.lt("number_of_pages", 300), Filters.gte("number_of_pages", 200));
Optional<Row> result = table.findOne(filter);
System.out.println(result);
}
}
curl -sS -L -X POST "API_ENDPOINT/api/json/v1/KEYSPACE_NAME/TABLE_NAME" \
--header "Token: APPLICATION_TOKEN" \
--header "Content-Type: application/json" \
--data '{
"findOne": {
"filter": {"$and": [
{"number_of_pages": {"$lt": 300}},
{"number_of_pages": {"$gte": 200}}
]}
}
}'