Afaik 你不能通过 HTTP api 做到这一点,
正如 Christian 提到的,您可以使用范围查询,但您不需要替代索引,因为您已经拥有可以$key
作为索引字段引用的主键索引:
olav@nyx ~ (master *%) » curl http://nyx:8098/riak/test/20120931 -d "31. Sep 2012"
olav@nyx ~ (master *%) » curl http://nyx:8098/riak/test/20121002 -d "02. Oct 2012"
olav@nyx ~ (master *%) » curl http://nyx:8098/riak/test/20121021 -d "21. Oct 2012
olav@nyx ~ (master *%) » curl http://nyx:8098/riak/test/20121102 -d "The future"
olav@nyx ~ (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).