# Parent Child Bool Search problem

**URL:** <https://discuss.elastic.co/t/parent-child-bool-search-problem/42150>\
**Category:** Elasticsearch\
**Created:** [February 18, 2016, 3:18pm UTC](https://discuss.elastic.co/t/parent-child-bool-search-problem/42150 "2016-02-18T15:18:43Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cmk1523](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/cmk1523/32/6474_2.png) [@cmk1523](https://discuss.elastic.co/u/cmk1523)\
**Post date:** [February 18, 2016, 3:18pm UTC](https://discuss.elastic.co/t/parent-child-bool-search-problem/42150/1 "2016-02-18T15:18:43Z")

</div>

I have many children per parent document. For example, a parent is a book and each contributor towards the book is a separate child.

One of my successful queries is to find all books that have a certain contributor name. But what doesn't work is trying to find books that have both contributor name A and contributor name B. What I think is happening is ES is asking each child: do you have contributor name A and contributor name B? Which obviously is always false because each child can only be a single contributor. Does anyone know how to write the query I want in this parent/child relationship?

I had this working back when I tried a nested document model because the children field (of a book model) had all the contributors in a single array/list.

Having a single child with all the contributors in a list not an option because "contributors" are constantly coming in (ok ok, so I'm not really dealing with books & contributors) and really defeats the purpose of parent/child... right?

UPDATE:  
The key was to format the query like so...  
query:{  
bool:{  
must:[  
{  
has\_child:{  
type:"contributors",  
query:{  
bool:{  
must:[  
{  
term:{  
contributorName:"aaa"  
}  
}  
]  
}  
}  
}  
},  
{  
has\_child:{  
type:"contributors",  
query:{  
bool:{  
must:[  
{  
term:{  
contributorName:"bbb"  
}  
}  
]  
}  
}  
}  
}  
]  
}  
}

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [July 5, 2017, 11:15pm UTC](https://discuss.elastic.co/t/parent-child-bool-search-problem/42150/2 "2017-07-05T23:15:11Z")

</div>


