Emulating composite index queries with secondary indexes and key filters

Olav Frengstad olav at fwt.no
Tue Aug 28 07:08:35 EDT 2012


I'm looking to use riak to store time series. So naturaly i'm in the
processes of validating all possible methods this query. A object
has a id, origin, timestamp and type. The query in question is to
select all object within a time range that originated from "origin"
and has a certain "type".

The current plan is to store the timestamp as a secondary index and
then have composite keys responsible for matching origin/type predicate.

A key would look like this: "<id>:<origin>:<type>".

To query one would just pipe the 2i query to key filter map reduce:

curl -X POST -H "Content-Type: application/json" -d '{"inputs":{
"bucket" : "seriesx", "index" : "timestamp_int", "start" : 123,
"end" : 456, "key_filters" : [["ends_with", "<origin>:<type>"]]}}'

In regards to this "imaginary" solution i have a few questions:
  1) is this possible, or does key filter only work on a bucket?
  2) Would this be a efficient solution, considering the 2i query
     will return 10k+ results? the reduce should cut that in half.
  3) What other options to i have for querying this? Obviously i can
     use Riak search, but the term based indexing puts me off. Other
     option is building this manually with empty object just linking.

Med Vennlig Hilsen
Olav Frengstad

Systemutvikler // FWT
+47 920 42 090

More information about the riak-users mailing list