This discussion is archived
3 Replies Latest reply: Nov 9, 2011 10:29 AM by greybird RSS

Search keys

899218 Newbie
Currently Being Moderated
Hello all

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...
  • 1. Re: Search keys
    Charles Lamb Pro
    Currently Being Moderated
    896215 wrote:
    Hello all

    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...
    Hello,

    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.

    Charles
  • 2. Re: Search keys
    899218 Newbie
    Currently Being Moderated
    Thank you. As I expected.

    I think of [the following way|http://pastebin.mozilla-russia.org/109407] to resolve my problem. What do you think?
  • 3. Re: Search keys
    greybird Expert
    Currently Being Moderated
    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.

    --mark                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                                               

Legend

  • Correct Answers - 10 points
  • Helpful Answers - 5 points