holmes840
holmes840

Reputation: 1083

Limit number of records in aerospike select query

I am trying to query using aql (Aerospike Query Language) in aerospike set.
Suppose there are 1000 records and I want to read any 10 records. Usually I would query something like :

select * from test.demo limit 10;

How do I query the same using aql ?

Upvotes: 12

Views: 8474

Answers (2)

Ronen Botzer
Ronen Botzer

Reputation: 7117

2024 Edit on a really old (and obsolete) question Yes, AQL can use LIMIT. See https://aerospike.com/docs/tools/aql/querying_records#filter-on-indexed-bins

The JDBC driver can do a limit too. See https://github.com/aerospike/aerospike-jdbc/blob/main/docs/examples.md

Original answer from 2014:

At the moment you cannot do that in aql, but you can use the BETWEEN predicate to define a range to the query.

When you use the C-client (or one of the language clients that wrap around it) a scan (as_scan_foreach) can be limited by setting the percentage field of the as_scan struct.

Upvotes: 5

Helipilot50
Helipilot50

Reputation: 227

Here is an example of 'scan' in Java.

    **this.client.scanAll(scanPolicy, "test", "demo", new ScanCallback() {

        @Override
        public void scanCallback(Key key, Record record) throws AerospikeException {
            System.out.println("Record: " + record);

        }
    });**

That there is no order implied in a 'scan', records are returned to your application in the order they are received from the nodes in the cluster.

Upvotes: 1

Related Questions