Query Index
Catalyst enables you to query a NoSQL index and retrieve data by identifying the items using the primary keys of the index. Indexing allows you to execute alternate queries on the table data without making use of the primary keys of the main table. You can configure indexes from the Catalyst console. You can use just the partition key or a combination of the partition key and sort key of the index to retrieve an item.
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.
Operators | Notation |
---|---|
CONTAINS | contains |
NOT_CONTAINS | not_contains |
BEGINS_WITH | begins_with |
ENDS_WITH | ends_with |
IN | in |
NOT_IN | not_in |
BETWEEN | between |
NOT_BETWEEN | not_between |
EQUALS | equals |
NOT_EQUALS | not_equals |
GREATER_THAN | greater_than |
LESS_THAN | less_than |
GREATER_THAN_OR_EQUALS | greater_equal |
LESSER_THAN_OR_EQUALS | less_equal |
AND | AND |
OR | OR |
In the example below, the query is performed with an index referenced by its unique Index ID. The query identifies the items using the index’s partition key fruitColor and specifying the condition value as “yellow”. We also specify an additional condition with the attribute fruitType matching “citrus”. The query is done using the query_index() method.
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.
copy# Query a NoSQL table index to fetch the items identified by the partition key fruitColour with the value "yellow"# Pass the index's unique ID cres = table.query_index('6759000000740017', { # Set consistent_read to true to query from master. If set to false, it is queried from slave. 'consistent_read': 'true',# Set forward_scan 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 query the items with 'key_condition': { 'attribute': 'fruitColor', 'operator': 'equals', 'value': { 'S': 'yellow' } }, # Define additional conditions to query the data with, using group operators 'other_condition': { 'group_operator': 'AND', 'group': [ { 'attribute': 'fruitType', 'operator': 'equals', 'value': { 'S': 'citrus' } } ] } }) print(res)
Last Updated 2025-06-20 16:21:48 +0530 +0530
Yes
No
Send your feedback to us