# Search on top\_children and parent fields

**URL:** <https://discuss.elastic.co/t/search-on-top-children-and-parent-fields/8788>\
**Category:** Elasticsearch\
**Created:** [August 20, 2012, 1:57pm UTC](https://discuss.elastic.co/t/search-on-top-children-and-parent-fields/8788 "2012-08-20T13:57:45Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Maik\_Broxterman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/maik_broxterman/32/884_2.png) [@Maik\_Broxterman](https://discuss.elastic.co/u/Maik_Broxterman)\
**Post date:** [August 20, 2012, 1:57pm UTC](https://discuss.elastic.co/t/search-on-top-children-and-parent-fields/8788/1 "2012-08-20T13:57:45Z")

</div>

I'm using top\_children for finding parent documents by the content of the  
child. This works good for me, but I want to be able to search for a field  
of the parent too, in the same query. I'm thinking about something like  
this:

curl -XPOST 'localhost:9200/default/topic/\_search?pretty=true' -d '  
{  
"query": {  
"top\_children" : {  
"type": "post",  
"query": {  
"text" : {  
"content" : {  
"query" : "parent child",  
"operator" : "and",  
"fuzziness": 0.5  
}  
}  
},  
"incremental\_factor":5  
},  
"text": {  
"title" : {  
"query" : "parent child",  
"operator" : "and"  
}  
}  
}'

but it geves me an error:

Parse Failure [No parser for element [title]]

while something like:

curl -XPOST 'localhost:9200/default/topic/\_search?pretty=true' -d '  
{  
"query": {  
"text": {  
"title" : {  
"query" : "parent child",  
"operator" : "and"  
}  
}  
}'

works (so without the top children).

Title is a field of topic and content a field of post.

So: how do I combine top children with a search on the parents' own fields?

Thanks in advance.

--

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [August 23, 2012, 10:53am UTC](https://discuss.elastic.co/t/search-on-top-children-and-parent-fields/8788/2 "2012-08-23T10:53:45Z")

</div>

Hi Maik

> curl -XPOST 'localhost:9200/default/topic/\_search?pretty=true' -d '  
> {  
> "query": {  
> "top\_children" : {  
> },  
> "text": {  
> },  
> }'

You can't have two top level queries. You need to nest you top\_children  
and text queries in a bool query

clint

--

---

<div class="post-metadata">

**Author:** ![Maik\_Broxterman](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/maik_broxterman/32/884_2.png) [@Maik\_Broxterman](https://discuss.elastic.co/u/Maik_Broxterman)\
**Post date:** [August 23, 2012, 2:10pm UTC](https://discuss.elastic.co/t/search-on-top-children-and-parent-fields/8788/3 "2012-08-23T14:10:23Z")

</div>

Aah, nice.

Cool, thanks! It seems it works now.

On Thursday, August 23, 2012 12:53:45 PM UTC+2, Clinton Gormley wrote:

> Hi Maik
> 
> > curl -XPOST 'localhost:9200/default/topic/\_search?pretty=true' -d '  
> > {  
> > "query": {  
> > "top\_children" : {  
> > },  
> > "text": {  
> > },  
> > }'
> 
> You can't have two top level queries. You need to nest you top\_children  
> and text queries in a bool query
> 
> clint

--

---

<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 6, 2017, 3:15am UTC](https://discuss.elastic.co/t/search-on-top-children-and-parent-fields/8788/4 "2017-07-06T03:15:20Z")

</div>


