AFAIK你無法通過HTTP API做到這一點,
基督教提到你可以使用範圍查詢,但你並不需要一個替代指標,你已經可以通過被引用的主鍵索引$key
爲索引字段:
[email protected] ~ (master *%) » curl http://nyx:8098/riak/test/20120931 -d "31. Sep 2012"
[email protected] ~ (master *%) » curl http://nyx:8098/riak/test/20121002 -d "02. Oct 2012"
[email protected] ~ (master *%) » curl http://nyx:8098/riak/test/20121021 -d "21. Oct 2012
[email protected] ~ (master *%) » curl http://nyx:8098/riak/test/20121102 -d "The future"
[email protected] ~ (master *%) » curl -X POST -H "content-type: application/json" \
-d @- http://localhost:8098/mapred \
<<EOF
{ "inputs":{
"bucket":"test"
, "index":"\$key"
, "start":"20121001"
, "end":"20121101"
}
, "query":[{
"reduce":{
"language":"erlang"
, "module":"riak_kv_mapreduce"
, "function":"reduce_identity"
, "keep":true
}
}]
}
EOF
# ...
[["test","20121021"],["test","20121002"]]
如果你真的想和你的鍵過濾器可以使用Erlang的PB客戶端,做沿着這些線路(你需要riak_kv
在你的代碼路徑)的東西:
{ok, Pid} = riakc_pb_socket:start_link("127.0.0.1", 8087),
Index = {index, <<"test1">>, <<"field_int">>, <<"123">>},
{ok, Filter} = riak_kv_mapred_filters:build_filter([[<<"ends_with">>,"1"]]).
MapReduce = [
{ reduce
, {qfun, fun(X, F) -> lists:filter(fun({A, B}) -> F(B) end, X) end}
, riak_kv_mapred_filters:compose(Filter)
, true}],
riakc_pb_socket:mapred(Pid, Index, MapReduce).
感謝Christian。將日期添加到秒指數 –