後方に廃止予定があり、/riak/{bucket}
メソッドは廃止され、/buckets/{bucket}
現在の URL スキームです。
クエリcurl http://localhost:8098/buckets/{bucket}/index/{index}/{value}
はキーのリストを返しますが、それらの値は返さないことに注意してください。
いくつかの例:
最初にいくつかのデータを生成します。
# for i in {1..1000}; do
num=$RANDOM;
curl 172.31.0.3:8098/buckets/index_test/keys/key$i -XPUT \
-H 'content-type: text/plain' \
-H 'x-riak-index-random_int:'$num \
-d "{\"value\":$num}";
done
乱数が 10000 ~ 10500 のキーを検索します。
# curl 172.31.0.3:8098/buckets/index_test/index/random_int/10000/10500
{"keys":["key334","key93","key51","key232","key427","key177","key504","key813","key472","key618","key405","key558"]}
各項目にインデックスが付けられた値を取得します。
# curl 172.31.0.3:8098/buckets/index_test/index/random_int/10000/10500\?return_terms=true
{"results":[{"10189":"key334"},{"10089":"key93"},{"10013":"key558"},{"10088":"key405"},{"10057":"key51"},{"10353":"key618"},{"10282":"key472"},{"10194":"key504"},{"10301":"key232"},{"10219":"key813"},{"10311":"key427"},{"10278":"key177"}]}
しかし、実際の JSON を取得するには、KV ストアから値を取得する必要があります。
# curl 172.31.0.3:8098/buckets/index_test/keys/key334
{"value":10189}
これは、クエリがあまり頻繁に実行されず、ノードが負荷を処理できる場合は、MapReduce を介して実行できます。
# curl 172.31.0.3:8098/mapred -XPOST -H 'content-type: application/json' \
-d '{"inputs":{"bucket":"index_test","index":"random_int","start":10000,"end":10500},'\
'"query":[{"map":{"language":"javascript",'\
'"source":"function(Obj){return [Obj.values[0].data]}"}}]}'
["{value:10189}","{value:10013}","{value:10311}","{value:10278}","{value:10057}","{value:10219}","{value:10353}","{value:10089}","{value:10088}","{value:10301}","{value:10282}","{value:10194}"]
# curl 172.31.0.3:8098/mapred -XPOST -H 'content-type: application/json'\
-d '{"inputs":{"bucket":"index_test","index":"random_int","start":10000,"end":10500},'\
'"query":[{"map":{"language":"javascript",'\
'"source":"function(Obj){return [{\"key\":Obj.key,\"data\":Obj.values[0].data}]}"}}]}'
[{"key":"key558","data":"{value:10013}"},{"key":"key334","data":"{value:10189}"},{"key":"key51","data":"{value:10057}"},{"key":"key427","data":"{value:10311}"},{"key":"key177","data":"{value:10278}"},{"key":"key813","data":"{value:10219}"},{"key":"key93","data":"{value:10089}"},{"key":"key405","data":"{value:10088}"},{"key":"key232","data":"{value:10301}"},{"key":"key618","data":"{value:10353}"},{"key":"key504","data":"{value:10194}"},{"key":"key472","data":"{value:10282}"}]