3

使用 Riak 1.4.7

我有一个文档,它的属性是嵌入文档的数组。以下是该文档的示例:

{"prospect":true, "name":"HzNUeioPYynsGdXL6iSFvQ",
"contact_email":"contact@HzNUeioPYynsGdXL6iSFvQ.gr",
"e_shops":[{"store_url":"www.store.url.com","display_name":"hello there"},
           {"store_url":"www.store2.url.com","display_name":"hello2 there"}]
}

相应的存储桶已启用索引并且工作正常。例如,以下搜索命令可以毫无问题地定位对象:

search-cmd search index_name contact_email:contact@HzNUeioPYynsGdXL6iSFvQ.gr

这里的问题是我如何通过store_url示例进行搜索。

store_url是嵌入文档的属性,反过来,它是主文档的数组属性的元素。

1)我是否必须指定一个自定义模式文件才能让索引索引这些属性?

2) 我是否必须使用某种特殊语法进行查询?

4

1 回答 1

1

默认的 JSON 提取器应该通过将数组中的所有值连接到一个空格分隔的列表中来处理这种情况。嵌套名称通过用下划线连接它们来处理。所以在这种情况下,该字段e_shops_store_url将包含www.store.url.com www.store2.url.com. 您可以正常查询该字段。

我跑了一个简单的例子来演示:

root@node1:~# search-cmd install searchtest

 :: Installing Riak Search <--> KV hook on bucket 'searchtest'.
root@node1:~# curl 172.31.0.1:8098/buckets/searchtest/keys/test1 \
-XPUT -H"content-type:application/json" \
-d '{"prospect":true, "name":"HzNUeioPYynsGdXL6iSFvQ",
> "contact_email":"contact@HzNUeioPYynsGdXL6iSFvQ.gr",
> "e_shops":[{"store_url":"www.store.url.com","display_name":"hello there"},
>            {"store_url":"www.store2.url.com","display_name":"hello2 there"}]
> }'
root@node1:~# curl 172.31.0.1:8098/buckets/searchtest/keys/test2 \
-XPUT -H"content-type:application/json" \
-d '{"prospect":true, "name":"-HzNUeioPYynsGdXL6iSFvQ",
>"contact_email":"contact@-HzNUeioPYynsGdXL6iSFvQ.gr",
>"e_shops":[{"store_url":"www.store.url.com","display_name":"hello there"},
>           {"store_url":"www.store3.url.com","display_name":"hello3 there"}]
>}'
root@node1:~# search-cmd search-doc searchtest e_shops_store_url:www.store.url.com

 :: Searching for 'e_shops_store_url:www.store.url.com' / '' in searchtest...

------------------------------

index/id: searchtest/test1
<<"contact_email">> => <<"contact@HzNUeioPYynsGdXL6iSFvQ.gr">>
<<"e_shops_display_name">> => <<"hello there hello2 there">>
<<"e_shops_store_url">> => <<"www.store.url.com www.store2.url.com">>
<<"name">> => <<"HzNUeioPYynsGdXL6iSFvQ">>
<<"prospect">> => <<"true">>

------------------------------

index/id: searchtest/test2
<<"contact_email">> => <<"contact@-HzNUeioPYynsGdXL6iSFvQ.gr">>
<<"e_shops_display_name">> => <<"hello there hello3 there">>
<<"e_shops_store_url">> => <<"www.store.url.com www.store3.url.com">>
<<"name">> => <<"-HzNUeioPYynsGdXL6iSFvQ">>
<<"prospect">> => <<"true">>

------------------------------

 :: Found 2 results.
 :: Maximum score "0.353553".
于 2014-12-29T19:07:25.283 回答