我无法运行erlang函数,因此尝试使用以下Javascript:
curl -XPOST http://localhost:8098/mapred \
-H "Content-Type: application/json" \
-d @- \
<<EOF
{
"inputs":"logs",
"query":[{
"map":{
"language":"javascript",
"source":"function(riakObject, keydata, arg) {
var m = riakObject.values[0].data.match(/^INFO.*cart/);
return [(m ? m.length : 0 )];
}"
},
"reduce":{
"language":"javascript",
"source":"function(values, arg){
return [values.reduce(
function(total, v){ return total + v; }, 0)
];
}"
}
}]
}
EOF
似乎也不适用于JS。 Shell只是挂起而根本不返回。请建议。
**更新**
今天,当我尝试时,我看到以下错误:
An error occurred parsing the "query" field.
["Unrecognized format of query phase:\n ",
[123,
[34,<<"map">>,34],
58,
[123,
[34,<<"language">>,34],
58,
[34,<<"javascript">>,34],
44,
[34,<<"source">>,34],
58,
[34,
<<"function(riakObject, keydata, arg) { var m = riakObject.values[0].data.match(/^INFO.*Milk/); return [(m ? m.length : 0 )]; }">>,
34],
125],
44,
[34,<<"reduce">>,34],
58,
[123,
[34,<<"language">>,34],
58,
[34,<<"javascript">>,34],
44,
[34,<<"source">>,34],
58,
[34,
<<"function(values, arg){ return [values.reduce( function(total, v){ return total + v; }, 0) ]; }">>,
34],
125],
125],
"\n\nValid formats are:\n {\"map\":{...spec...}}\n {\"reduce\":{...spec...}}\n {\"link:{...spec}}\n"]
答案 0 :(得分:1)
查询元素应该是一个对象列表,用&#34; map&#34;并且&#34;减少&#34;在谨慎的对象中。您的JSON将它们作为同一对象的属性。
这对我有用:
curl -XPOST http://localhost:8098/mapred -H "Content-Type: application/json" -d '{
"inputs":"logs",
"query":[
{"map":{
"language":"javascript",
"source":"function(riakObject, keydata, arg) {
var m = riakObject.values[0].data.match(/^INFO.*cart/);
return [(m ? m.length : 0 )];
}"
}},
{"reduce":{
"language":"javascript",
"source":"function(values, arg){
return [values.reduce(
function(total, v){ return total + v; }, 0)
];
}"
}}
]
}'