Solr - Search parent having multiple child documents

666 views Asked by At

I have a Solr index with structure as below.

{
"id": "1",
"bookName_s": "Core Concepts",
"bookDescription_s": "This is the description",
"isbn_s": "ABCD:123",    
"reviews": [
  {
    "id": "2",
    "Name_s": "review1",
    "detail_s": "sample review"
  }
],
"students": [
  {
    "id": "3",
    "Name_s": "student1",
    "student_s": "test student"
  }
]

}

How do i search for parent that has a reviewer with Name_s as 'review1' and student with Name_s as 'student'.

I tried parent block chain query like below but nothing seems to work -

q=({!parent which="*:* -_nest_path_:*"}(+_nest_path_:\/reviews +Name_s:*rev*)) AND ({!parent which="*:* -_nest_path_:*"}(+_nest_path_:\/students +Name_s:*stu*)) 

q=({!parent which="*:* -_nest_path_:*"}(+_nest_path_:\/reviews +Name_s:*rev*)(+_nest_path_:\/students +Name_s:*stu*))

Is there a way i can acheive this using the q operator instead of fq parameter? thanks

1

There are 1 answers

1
teja_98666 On

Based on EricLavault suggestion i modified the index to include type of the object in the index like below -

{
    "id": "1",
    "bookName_s": "Core Concepts",
    "bookDescription_s": "This is the description",
    "isbn_s": "ABCD:123",
    "type_s":"book"    
    "reviews": [
      {
        "id": "2",
        "Name_s": "review1",
        "detail_s": "sample review",
        "type":"review"
      }
    ],
    "students": [
      {
        "id": "3",
        "Name_s": "student1",
        "type":"student",
        "student_s": "test student"
      }
    ]
    }

and below queries worked.

{!parent which="type:book"}(type:review AND Name_s:review1) OR (type:student AND Name_s:student1)

returns all books with review1 and student1