Range Query using Index of Type String


Aerospike Rookie.

aerospike client context: golang

Use Case:
we have a Set with a bin Time of data type String. We store Time String in the format specified by RFC-3339( YYYY-MM-DDThh:mm:ssZ), which is a specific profile of ISO-8601 Datetime format. Essentially, Time is sortable as its String Values lexicographical order aligns with the Chronological Order.

We created an Index CREATE INDEX idx_timestamp ON ns.set-Name (Time) STRING

Given that in filter.go API NewRangeFilter the String ranges are not supported,

I tried a combination of expression.go ExpGreater and ExpLess in a query with Time values to achieve the same result as NewRangeFilter.

Is the Query using the Two Expressions ExpGreater and ExpLess from expression.go using the underlying index idx_timestamp?

How can I be assured of that ?

Thanks much

In this case, you are going through every record and records matching the expression condition are returned. idx_timestamp is not used in your query. This query is not a secondary index query, rather it is being executed as a Primary Index query, previously referred to as a scan.

A secondary index on a string data type is stored in the SI b-tree as the hash value of the string. Only equality queries for String can therefore utilize the b-tree and return the associated record(s).

If you want to use a range query with Secondary Index on Time, you will have to store the time value as an integer (e.g. seconds from an epoch? ) and then build a secondary index on it of type NUMERIC.

1 Like

Thanks @pgupta for quick clarification.