我是新的Riak,所以請原諒我的錯誤理解。無法使用地圖減少與riak
我能夠添加新條目並按鍵和索引執行查詢。但是我必須實現更復雜的查詢,所以我試圖使用MapReduce
。
我有我的應用程序級實體命名Volume
,對於現在只有簡單的領域:
public class Volume implements Comparable<Volume>, Serializable {
@RiakIndex(name = "id")
@JsonProperty("id")
private Integer id;
@RiakIndex(name = "name")
@RiakKey
private String name;
@RiakIndex(name = "created_at")
@JsonProperty("created_at")
private long createdAt;
// setters, getters....
}
這是我如何添加Volume
實例了Riak數據庫:
IRiakClient riakClient = RiakFactory.httpClient();
Bucket bucket = riakClient.fetchBucket(bucketName).execute();
for (int i = 0; i < n; i++) {
int id = i;
ManagedVolume volume = new ManagedVolume();
volume.setCreatedAt(System.currentTimeMillis());
volume.setId(id);
volume.setName("volume" + i);
bucket.store(volume).execute();
}
現在我可以檢索沒有像以下任何問題的實例。
Collection<String> col = backet.fetchIndex(IntIndex.named("id")).from(3).to(5).execute();
但所有嘗試使用MapReduce
失敗:
String str = riakClient.mapReduce(bucketName, "name: volume1")
.addMapPhase(new NamedJSFunction("Riak.mapValuesJson")).
execute().getResultRaw();
我試圖做到這一點無需添加Riak.mapValuesJson
,試圖修改查詢中使用id
而不是name
和包裹volume`` with quotes (
「名稱:\」音量\「」,
「name:\'volume \'」etc.) but nothing helps. I always get HTTP status 500 and the following error:
{「error」:「map_reduce_error」}'
在這裏我們堆棧跟蹤:
Exception in thread "main" com.basho.riak.client.RiakException: java.io.IOException: {"error":"map_reduce_error"}
at com.basho.riak.client.query.MapReduce.execute(MapReduce.java:81)
at com.infinidat.riak.TryRiak.search(TryRiak.java:288)
at com.infinidat.riak.TryRiak.main(TryRiak.java:66)
Caused by: java.io.IOException: {"error":"map_reduce_error"}
at com.basho.riak.client.raw.http.ConversionUtil.convert(ConversionUtil.java:589)
at com.basho.riak.client.raw.http.HTTPClientAdapter.mapReduce(HTTPClientAdapter.java:386)
at com.basho.riak.client.query.MapReduce.execute(MapReduce.java:79)
... 2 more
我在Riak的error.log
和console.log
中發現了以下記錄。
2013-07-23 19:14:12.451 [error] <0.194.0> Supervisor riak_pipe_builder_sup had child undefined started with {riak_pipe_builder,start_link,undefined} at <0.18058.4> exit with reason {{modfun,riak_search,mapred_search,[<<"VolumeBucket">>,<<"name: 1">>]},error,badarg,[{ets,lookup,[schema_table,<<"VolumeBucket">>],[]},{riak_search_config,get_schema,1,[{file,"src/riak_search_config.erl"},{line,69}]},{riak_search_client,parse_query,3,[{file,"src/riak_search_client.erl"},{line,40}]},{riak_search,parse_query,3,[{file,"src/riak_search.erl"},{line,59}]},{riak_search,mapred_search,3,[{file,"src/riak_search.erl"},{line,46}]},{riak_kv_mrc_pipe,send_inputs,3,[{file,"src/riak_kv_mrc..."},...]},...]} in context child_terminated
我相信我在這裏失去了一些東西。可能是配置問題?這是一個非常簡單的查詢。一旦這個工作正常,我顯然希望向更復雜的查詢前進。