Riak 搜索返回 "No index" 和“(23) 写入正文失败”
Riak search returning "No index" and "(23) Failed writing body"
我有一个测试系统,我已经创建并激活了 libraries
作为存储桶类型 clients
的搜索 属性。
➜ riak-2.1.0 curl http://localhost:8098/buckets/coding-with-riak/props
{"props":{"allow_mult":false,"basic_quorum":false,"big_vclock":50,"chash_keyfun":{"mod":"riak_core_util","fun":"chash_std_keyfun"},"dvv_enabled":false,"dw":"quorum","last_write_wins":false,"linkfun":{"mod":"riak_kv_wm_link_walker","fun":"mapreduce_linkfun"},"n_val":3,"name":"coding-with-riak","notfound_ok":true,"old_vclock":86400,"postcommit":[],"pr":0,"precommit":[],"pw":0,"r":"quorum","rw":"quorum","search_index":"libraries","small_vclock":50,"w":"quorum","write_once":false,"young_vclock":20}}%
➜ riak-2.1.0 bin/riak-admin bucket-type status clients
clients is active
active: true
allow_mult: true
basic_quorum: false
big_vclock: 50
chash_keyfun: {riak_core_util,chash_std_keyfun}
claimant: 'riak@127.0.0.1'
dvv_enabled: true
dw: quorum
last_write_wins: false
linkfun: {modfun,riak_kv_wm_link_walker,mapreduce_linkfun}
n_val: 3
notfound_ok: true
old_vclock: 86400
postcommit: []
pr: 0
precommit: []
pw: 0
r: quorum
rw: quorum
search_index: <<"libraries">>
small_vclock: 50
w: quorum
young_vclock: 20
我相信 我设置存储桶coding-with-riak
,使其为搜索做好准备:
➜ ~ curl http://localhost:8098/buckets/coding-with-riak/props
{"props":{"allow_mult":false,"basic_quorum":false,"big_vclock":50,"chash_keyfun":{"mod":"riak_core_util","fun":"chash_std_keyfun"},"dvv_enabled":false,"dw":"quorum","last_write_wins":false,"linkfun":{"mod":"riak_kv_wm_link_walker","fun":"mapreduce_linkfun"},"n_val":3,"name":"coding-with-riak","notfound_ok":true,"old_vclock":86400,"postcommit":[],"pr":0,"precommit":[],"pw":0,"r":"quorum","rw":"quorum","search_index":"libraries","small_vclock":50,"w":"quorum","write_once":false,"young_vclock":20}}%
但是当我尝试通过 Ruby 客户端或通过 cURL 进行搜索时,出现错误:
>> coding.keys
Riak::Bucket#keys is an expensive operation that should not be used in production.
=> ["ruby", "python", "go"]
>> results = client.search("coding-with-riak", "maintainer_s:*")
Riak::ProtobuffsErrorResponse: Expected success from Riak but received 0. No index <<"coding-with-riak">> found.
cURL 有类似的结果:
➜ curl "http://localhost:8098/search/query/libraries?wt=json&q=popular_b:true"
(23) Failed writing body
我错过了什么?我已经多次遍历 search how-to,但找不到我遗漏的东西。请注意,我在激活搜索属性后确实重新启动了。
#riak IRC 上的好心人纠正了两个不同的问题。
在 ruby 方面,我需要提供搜索索引,而不是存储桶:
>> results = client.search("libraries", "maintainer_s:basho")
=> {"max_score"=>1.8109302520751953, "num_found"=>1, "docs"=>[{"score"=>"1.81093030000000010382e+00", "_yz_rb"=>"coding-with-riak", "_yz_rt"=>"default", "_yz_rk"=>"ruby", "_yz_id"=>"1*default*coding-with-riak*ruby*56", "name_s"=>"Ruby Client", "maintainer_s"=>"basho", "popular_b"=>"true"}]}
对于 cURL 查询,由于我上面使用的 localhost
的主机文件映射,我遇到了编码问题。使用 127.0.0.1
有效:
➜ ~ curl "http://127.0.0.1:8098/search/query/libraries?wt=json&q=popular_b:true" | json_pp
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 866 100 866 0 0 81169 0 --:--:-- --:--:-- --:--:-- 86600
{
"responseHeader" : {
"QTime" : 9,
"params" : {
"shards" : "127.0.0.1:8093/internal_solr/libraries",
"wt" : "json",
"127.0.0.1:8093" : "_yz_pn:63 OR (_yz_pn:60 AND (_yz_fpn:60)) OR _yz_pn:59 OR _yz_pn:56 OR _yz_pn:53 OR _yz_pn:50 OR _yz_pn:47 OR _yz_pn:44 OR _yz_pn:41 OR _yz_pn:38 OR _yz_pn:35 OR _yz_pn:32 OR _yz_pn:29 OR _yz_pn:26 OR _yz_pn:23 OR _yz_pn:20 OR _yz_pn:17 OR _yz_pn:14 OR _yz_pn:11 OR _yz_pn:8 OR _yz_pn:5 OR _yz_pn:2",
"q" : "popular_b:true"
},
"status" : 0
},
"response" : {
"maxScore" : 1.2513144,
"docs" : [
{
"_yz_id" : "1*default*coding-with-riak*go*50",
"_yz_rt" : "default",
"popular_b" : true,
"name_s" : "Go Client",
"_yz_rb" : "coding-with-riak",
"_yz_rk" : "go",
"maintainer_s" : "community"
},
{
"_yz_id" : "1*default*coding-with-riak*ruby*56",
"_yz_rt" : "default",
"popular_b" : true,
"name_s" : "Ruby Client",
"_yz_rb" : "coding-with-riak",
"maintainer_s" : "basho",
"_yz_rk" : "ruby"
}
],
"start" : 0,
"numFound" : 2
}
}
我有一个测试系统,我已经创建并激活了 libraries
作为存储桶类型 clients
的搜索 属性。
➜ riak-2.1.0 curl http://localhost:8098/buckets/coding-with-riak/props
{"props":{"allow_mult":false,"basic_quorum":false,"big_vclock":50,"chash_keyfun":{"mod":"riak_core_util","fun":"chash_std_keyfun"},"dvv_enabled":false,"dw":"quorum","last_write_wins":false,"linkfun":{"mod":"riak_kv_wm_link_walker","fun":"mapreduce_linkfun"},"n_val":3,"name":"coding-with-riak","notfound_ok":true,"old_vclock":86400,"postcommit":[],"pr":0,"precommit":[],"pw":0,"r":"quorum","rw":"quorum","search_index":"libraries","small_vclock":50,"w":"quorum","write_once":false,"young_vclock":20}}%
➜ riak-2.1.0 bin/riak-admin bucket-type status clients
clients is active
active: true
allow_mult: true
basic_quorum: false
big_vclock: 50
chash_keyfun: {riak_core_util,chash_std_keyfun}
claimant: 'riak@127.0.0.1'
dvv_enabled: true
dw: quorum
last_write_wins: false
linkfun: {modfun,riak_kv_wm_link_walker,mapreduce_linkfun}
n_val: 3
notfound_ok: true
old_vclock: 86400
postcommit: []
pr: 0
precommit: []
pw: 0
r: quorum
rw: quorum
search_index: <<"libraries">>
small_vclock: 50
w: quorum
young_vclock: 20
我相信 我设置存储桶coding-with-riak
,使其为搜索做好准备:
➜ ~ curl http://localhost:8098/buckets/coding-with-riak/props
{"props":{"allow_mult":false,"basic_quorum":false,"big_vclock":50,"chash_keyfun":{"mod":"riak_core_util","fun":"chash_std_keyfun"},"dvv_enabled":false,"dw":"quorum","last_write_wins":false,"linkfun":{"mod":"riak_kv_wm_link_walker","fun":"mapreduce_linkfun"},"n_val":3,"name":"coding-with-riak","notfound_ok":true,"old_vclock":86400,"postcommit":[],"pr":0,"precommit":[],"pw":0,"r":"quorum","rw":"quorum","search_index":"libraries","small_vclock":50,"w":"quorum","write_once":false,"young_vclock":20}}%
但是当我尝试通过 Ruby 客户端或通过 cURL 进行搜索时,出现错误:
>> coding.keys
Riak::Bucket#keys is an expensive operation that should not be used in production.
=> ["ruby", "python", "go"]
>> results = client.search("coding-with-riak", "maintainer_s:*")
Riak::ProtobuffsErrorResponse: Expected success from Riak but received 0. No index <<"coding-with-riak">> found.
cURL 有类似的结果:
➜ curl "http://localhost:8098/search/query/libraries?wt=json&q=popular_b:true"
(23) Failed writing body
我错过了什么?我已经多次遍历 search how-to,但找不到我遗漏的东西。请注意,我在激活搜索属性后确实重新启动了。
#riak IRC 上的好心人纠正了两个不同的问题。
在 ruby 方面,我需要提供搜索索引,而不是存储桶:
>> results = client.search("libraries", "maintainer_s:basho")
=> {"max_score"=>1.8109302520751953, "num_found"=>1, "docs"=>[{"score"=>"1.81093030000000010382e+00", "_yz_rb"=>"coding-with-riak", "_yz_rt"=>"default", "_yz_rk"=>"ruby", "_yz_id"=>"1*default*coding-with-riak*ruby*56", "name_s"=>"Ruby Client", "maintainer_s"=>"basho", "popular_b"=>"true"}]}
对于 cURL 查询,由于我上面使用的 localhost
的主机文件映射,我遇到了编码问题。使用 127.0.0.1
有效:
➜ ~ curl "http://127.0.0.1:8098/search/query/libraries?wt=json&q=popular_b:true" | json_pp
% Total % Received % Xferd Average Speed Time Time Time Current
Dload Upload Total Spent Left Speed
100 866 100 866 0 0 81169 0 --:--:-- --:--:-- --:--:-- 86600
{
"responseHeader" : {
"QTime" : 9,
"params" : {
"shards" : "127.0.0.1:8093/internal_solr/libraries",
"wt" : "json",
"127.0.0.1:8093" : "_yz_pn:63 OR (_yz_pn:60 AND (_yz_fpn:60)) OR _yz_pn:59 OR _yz_pn:56 OR _yz_pn:53 OR _yz_pn:50 OR _yz_pn:47 OR _yz_pn:44 OR _yz_pn:41 OR _yz_pn:38 OR _yz_pn:35 OR _yz_pn:32 OR _yz_pn:29 OR _yz_pn:26 OR _yz_pn:23 OR _yz_pn:20 OR _yz_pn:17 OR _yz_pn:14 OR _yz_pn:11 OR _yz_pn:8 OR _yz_pn:5 OR _yz_pn:2",
"q" : "popular_b:true"
},
"status" : 0
},
"response" : {
"maxScore" : 1.2513144,
"docs" : [
{
"_yz_id" : "1*default*coding-with-riak*go*50",
"_yz_rt" : "default",
"popular_b" : true,
"name_s" : "Go Client",
"_yz_rb" : "coding-with-riak",
"_yz_rk" : "go",
"maintainer_s" : "community"
},
{
"_yz_id" : "1*default*coding-with-riak*ruby*56",
"_yz_rt" : "default",
"popular_b" : true,
"name_s" : "Ruby Client",
"_yz_rb" : "coding-with-riak",
"maintainer_s" : "basho",
"_yz_rk" : "ruby"
}
],
"start" : 0,
"numFound" : 2
}
}