简体   繁体   中英

Riak: query array of 2i through Map Reduce

Can I query an array of secondary indexes in a Map Reduce job in Riak, instead of just the one key? I want to do something like this:

"inputs": {
    "bucket": myBycket,
        "index": "myIndex",
        "key": key + " OR " + key + " OR " + key
    },
    "query": [{
        "map": {
            "language":"javascript",
            "name":"Riak.mapValuesJson"
        }
    }]
}

But I have not found any support for it. The keys are in no particular order, so I don't think that I can use ranged queries.

You could certainly handle this with Map Reduce. If you presort your target keys, you could limit the range and possibly improve performance.

{
 "inputs": {
    "bucket": myBycket,
    "index": "myIndex",
    "start": firstkey,
    "end": lastkey
    },
    "query": [{
        "map": {
            "language":"javascript",
            "source":"function(v) {
                        if (v.key == "key1" || v.key == "key2") {
                           return [<<put what you want returned here>>]
                        } else {
                           return []
                        }
                      }"
        }
    }]
}

You should note that according to the docs site javascript Map Reduce has been officially deprecated, so you may want to use Erlang functions for new development.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM