Solr过滤嵌套文档中的多个子项

时间:2018-03-02 17:14:09

标签: solr

我无法找到如何过滤掉嵌套文档中的相关子项并将其与父项一起返回,如:

返回所有包含attribute1 = value1和attribute1 = value2的子文档的父项,并仅返回父项的子项。

一个文档的结构如下所示:

{
 category: parent,
 attr1: a,
 attr2: b,
   _childDocuments_ : [
   {
        category:child,
        childAttr1: x,
        // many more
   },
   {
        category:child,
        childAttr1: y,
        // many more
   }, 
   {
   // more children but should not be returned
   }]
}

使用子变换器返回所有子项。在[child]转换器中使用多个childFilters没有任何效果(第一个取消第二个,忽略一个)。

示例查询将是

query='+attr1:(*)+{!parent which=category:parent}childAttr1:x 
       +{!parent which=category:parent}childAttr1:y', 
       'fl':'*,[child parentFilter=category:parent childFilter=childAttr1:x11]'

我使用JSON API进行查询,通过父属性对结果进行分组并对某些父属性进行过滤,但这不重要(imho)。

非常感谢你的时间,我希望这个问题写好。

1 个答案:

答案 0 :(得分:0)

我认为你正在寻找的是:

&q={!parent which=category:parent}(+field:value1 AND field:value2)

&fl=*,[child childFilter="field:value1 AND field:value2" parentFilter=category:parent]