0

I want to read records from Aerospike DB using Secondary index.
Could you please if its possible to read records using secondary index from a particular node ( rather than from all nodes --- Default Behavior )

I am looking to do this operation in Java. Could you please point appropriate document or source code for the same.

Tarun
  • 3,162
  • 3
  • 29
  • 45
  • The Java client has ScanNode but not a way to query a specific node. Plus, there's no point to it. You can however control by query policy how many nodes you process in parallel. – Ronen Botzer Jul 27 '18 at 01:42
  • As per documentation, I could query (of scan type ) on a particular node. That's a only reason why I was thinking if its possible to do the same using Secondary Index too. – Tarun Jul 27 '18 at 05:58

1 Answers1

4

Aerospike distributes all your records evenly across all nodes of your cluster. Lets say you have a 3 node cluster with 6 records as below and possible distribution by nodes shown for argument:

id - age - name  (On node)
1 - 30 - Jack ( on n1)
2 - 34 - Jill (on n3)
3 - 31 - Bill  (on n1)
4 - 29 - Jane  (on n2)
5 - 40 - Tim  (on n3)
6 - 20  - Nik  (on n2)

and you build a secondary index on age - and ask for all records where age between 28 and 32 -- the secondary index query will be sent to each node, and each node will send the records that match back to client. So, you can't issue a SI query and say find me all records where age is between 28 and 32 just on node n1. No can do - no such feature in Aerospike.

pgupta
  • 5,130
  • 11
  • 8
  • 1
    As per documentation, I could query (of scan type ) on a particular node. That's a only reason why I was thinking if its possible to do the same using Secondary Index too. – Tarun Jul 27 '18 at 05:58
  • 1
    You're applying RDBMS thinking to a non-relational database. Scans walk the primary index and do not require any secondary index. You can optionally attach a [predicate filter](https://www.aerospike.com/docs/guide/predicate.html) to a scan, which will then apply logic to each record's metadata or data, as the primary index is walked. A query _must have_ a secondary index to work at all. It indexes data in a record's bins, and the query uses that to apply a single predicate to a single secondary index. You can optionally attach a predicate filter to the records matched by the query predicate. – Ronen Botzer Jul 27 '18 at 14:32
  • Hmm .. run scan on a particular node only? AFAIK you cannot run a scan on one particular node only. You can run a scan through all nodes, one node at a time or running on all nodes in parallel. Now I am curious... – pgupta Jul 28 '18 at 01:55