2017-09-14 64 views
0

我在SOLR一些嵌套数据。如何筛选从子文档特定字段SOLR

{ 
    "name":["Abc"], 
    "age":[30], 
    "hobby":["singing"], 
    "_childDocuments_":[ 
    { 
     "college":["xyz"], 
     "year":[2015], 
     "id":"3752-22491", 
     "3.c.m.c-id":["256939"], 
     "2.c.m-id":["354291"], 
     "path":["3.c.m.ci"]}, 
    { 
     "subject":["history","science"], 
     "marks-1":[75], 
     "marks-2":[75], 
     "id":"3752-802126", 
     "2.c.m-id":["354291"], 
     "path":["2.c.m"]} 
    ]} 

我不是只得到标记-1标记-2从Solr的。当我搜索时,我发现整个数据都是作为响应。我只需要帮助获取这两个领域。

感谢您的帮助提前。

+0

你能告诉你当前的查询? – Mysterion

+0

我正在使用这个查询(http:// localhost:8983/solr/test/select?indent = on&highlight = true&start = 0&rows = 10&wt = json&hl = true&hl.method = unified&fl = *,[child parentFilter = path:1.c childFilter = “路径:* C *” 限制= 50] q =名:Abc ) – Learner

回答

0

你不能做到这一点与ChildDocTransformer,因为它的目的是过滤子文档显示,没有哪个田子文件返回的

而且,我敢肯定,这将是只是更容易在客户端或响应的转化过程中过滤掉这些领域,因为你不会在限制子文档领域获得任何性能改进。

但是,如果你仍然想这样做,通过Solr的查询,你应该使用subquery transformer像这样的东西:

solr/collection_name/select?fl=id,title_t,stars:[subquery] //enter mode for subquery 
&indent=on 
&q=title_t:* // this is the general query, here, just selecting book 
&stars.fl=stars_i // which fields from the child documents to return 
&stars.q={!prefix f=id v=$row.id} // subquery that you need to adapt 

我做的书/评论的收集和这个查询从here它的工作正好。但是,您需要修改子查询。这里的问题是,您只需要选择与父文档相对应的特定子文档。这可能是某种PARENT_ID或别的东西(我没有看到你的数据信息,所以你会需要它)的。

你为什么需要它?否则,每个主文件将包含下面ALL子文档,你将与子查询中进行选择。在我的示例中,我使用前缀查询,因为子文档的id由父文档的id组成。例如。

id:book1 

和,孩子ID是:

id:book1_r1