Query NoSQL Table

Catalyst enables you to query a NoSQL table and retrieve data by identifying the items using the primary keys of the table. For instance, you can use just the partition key or a combination of the partition key and sort key to retrieve the item.

Note: Catalyst enables you to retrieve a maximum of 100 items in bulk from a NoSQL table with pagination from a single SDK operation. You must use the start_key token received in the SDK response and construct the logic for pagination.

You can define the key condition that identifies the item by specifying the attributes, their required values, and the supported operator to be used. You can also specify additional conditions with the group operators.

The supported operators are represented as shown below.

OperatorsNotation
CONTAINScontains
NOT_CONTAINSnot_contains
BEGINS_WITHbegins_with
ENDS_WITHends_with
INin
NOT_INnot_in
BETWEENbetween
NOT_BETWEENnot_between
EQUALSequals
NOT_EQUALSnot_equals
GREATER_THANgreater_than
LESS_THANless_than
GREATER_THAN_OR_EQUALSgreater_equal
LESSER_THAN_OR_EQUALSless_equal
ANDAND
OROR

In the example below, the query is executed using the queryTable() method by identifying the items using the partition key fruitType and specifying the condition value as “citrus”. We also specify an additional condition with the attribute location matching “USA”.

Catalyst NoSQL also lets you define other elements of the query, such using consistent_read to indicate if the read operation must be done using the master or a slave cluster, limiting the number of rows to be returned, and specifying the sorting order as ascending.

Note: In the master-slave replication, the master contains all the data of the database, and the slave contains copies from the master. Performing a read operation from the slave can reduce the overall cost with the trade-off being a minor delay in the updated data being reflected.
copy
# Query a NoSQL table to fetch the items identified by the partition key fruitType with the value "citrus"
res = table.query_table(
 {
    # Set consistent_read to true to query from master. If set to false, it is queried from slave.
   'consistent_read': 'true',# Set forwardScan to true to sort the results in ascending order. Otherwise, it is sorted in the descending order.
   'forwardScan': 'true',# Limit the number of rows to be returned by specifying a value
   'limit': 10,# Define the key condition to identify items
   'key_condition': {
    'attribute': 'fruitType',
    'operator': 'equals',
    'value': {
     'S': 'citrus'
    }
   },
    # Specify additional conditions to query the table items using group operators
   'other_condition': {
    'group_operator': 'and',
    'group': [
     {
     'attribute': 'location',
     'operator': 'equals',
     'value': {
      'S': 'USA'
     }
     }
    ]
   } 
 })
print(res)

Last Updated 2026-11-04 15:40:44 +0530 IST