Reputation: 65
I am trying to implement the following functionality. I have a bucket where I am storing objects. One of the object field is timestamp. Now I want to retrieve the objects whose timestamp is between an interval like (20130605 08:00:00 to 20130605 08:05:00) I mean i need to get all the objects from 8.00 to 8.05.
Can I implement this using Map Reduce or using secondary indexes?
Another approach I am considering is that the bucket itself would be created like 20130605:0800:0805 and then store the objects under this bucket. So now, I dont want to implement conditional time interval based queries. Please suggest a way.
Upvotes: 0
Views: 184
Reputation: 1665
Depending on the type of data you are storing, there are a few options. As you correctly point out, secondary indexes is one way to approach this, as these support both exact match and range queries. You can e.g. create a binary index (possibly even an integer index) containing a timestamp as outlined in your example and then fetch based on a range query on this index.
If your data allows it, another option might be to store several objects in a single record and give this record a key that represents a specific time interval. This would allow you to retrieve records covering a specific time period directly using keys, which is very efficient and scales well. I have described this method for a possibly similar scenario here.
You would determine the period covered by a single record based on the amount and frequency of data inserted so that the size of the record does not grow too big (a couple of MB). You could e.g. collect all data for a minute in a single record and give it a key in the format 'YYYYMMDDHHMI'. If you were looking for all data covering the period 20130605 08:00 to 20130605 08:05, you would directly fetch records 201306050800, 201306050801, 201306050802, 201306050803 and 201306050804.
Upvotes: 3