This content has been marked as final. Show 3 replies
I need to search for the keys by last component. Is it possible? What can I do to avoid this?
For example, I have a keys like key/group1/group2/id and I want to be able to search keys by group1. But at the same time I need to search by id. If I move id to start of key (key/id/group1/group) then I will be unable to search by group...
You should iterate over all of the keys at the lowest possible level in the path ('key' in the first case and 'group2' in the second case) and then pattern match against each of those keys. Thenfor each matching key, retrieve the related record using get(). If you are iterating over keys with the same major path, it will be relatively fast since only one rep group will need to be queried.
Thanks for posting the relevant code that is easy to read.
What you have will work and it may be fine if findByCurrency is infrequent and does not need to be quick, or if the data set is not very large. However, you should be aware that the storeKeysIterator method must query every partition in the system, which could mean querying many nodes if you have a large system.
If you place key components in the minor key, so that you can use multiGetIKeys or multiGetIKeysIterator, the query will be more efficient. This is what Charlie referred to above.
However, also be careful not to store a large number of records (for example, thousands or more) under a single major key path value, because this will cause an uneven distribution of records among partitions.