# Problem with highlighting in has\_child query

**URL:** https://discuss.elastic.co/t/problem-with-highlighting-in-has-child-query/4633
**Category:** Elasticsearch
**Created:** [June 15, 2011, 8:00pm UTC](https://discuss.elastic.co/t/problem-with-highlighting-in-has-child-query/4633 "2011-06-15T20:00:10Z")
**Posts on this page:** 6
**Page:** 1

<div class="post-metadata">

### Author: ![Lar\_Mader](https://avatars.discourse-cdn.com/v4/letter/l/a6a055/32.png) [@Lar\_Mader](https://discuss.elastic.co/u/Lar_Mader)
#### Post date: [June 15, 2011, 8:00pm UTC](https://discuss.elastic.co/t/problem-with-highlighting-in-has-child-query/4633/1 "2011-06-15T20:00:10Z")

</div>

I am unable to get highlighting results when querying a field of type  
attachment in a child document using the has\_child query. However I  
am able to get the highlighting results if I query directly against  
the child document.

Is this supported, or am I doing something wrong?

The child document is of type "contentFiles" with a field called  
"file" of type attachment (for pdf file processed by the mapper-  
attachments). This query successfully returns highlight elements:

curl -XGET '[http://localhost:9201/foo\_acme/contentFiles/\_search](http://localhost:9201/foo_acme/contentFiles/_search)' -d  
'{"query":{"field":{"file" : "Account"}},"highlight":{"fields":  
{"file": {}}}}'

However when I try to query via the parent type "content" using a  
has\_child query, I get the search results but I don't get the  
highlight elements:

curl -XGET '[http://localhost:9201/foo\_acme/content/\_search](http://localhost:9201/foo_acme/content/_search)' -d  
'{"query": {"has\_child":{"type":"contentFiles", "query":{"field":  
{"file" : "Account"}},"highlight":{"fields":{"file":{}}}}}}'

I'm using elasticsearch version 0.16.2.

For completeness, here is my mapping for the contentFiles type, but I  
think the mapping is ok, since my first query works:  
{  
"contentFiles": {  
"\_source" : {  
"enabled" : false  
},  
"\_parent": {  
"type" : "content"  
},  
"properties" : {  
"file" : {  
"type" : "attachment",  
"fields" : {  
"file" : {"store" : "yes",  
"term\_vector" : "with\_positions\_offsets"}  
}  
}  
}  
}  
}

Thanks!  
Lar

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [June 16, 2011, 9:48pm UTC](https://discuss.elastic.co/t/problem-with-highlighting-in-has-child-query/4633/2 "2011-06-16T21:48:12Z")

</div>

You can't do highlighting on the content of a child document when using has\_child query, that idea for that is to just match and return the parent docs, and those will be the ones that will be highlighted... .

On Wednesday, June 15, 2011 at 11:00 PM, lmader wrote:

> I am unable to get highlighting results when querying a field of type  
> attachment in a child document using the has\_child query. However I  
> am able to get the highlighting results if I query directly against  
> the child document.
> 
> Is this supported, or am I doing something wrong?
> 
> The child document is of type "contentFiles" with a field called  
> "file" of type attachment (for pdf file processed by the mapper-  
> attachments). This query successfully returns highlight elements:
> 
> curl -XGET '[http://localhost:9201/foo\_acme/contentFiles/\_search](http://localhost:9201/foo_acme/contentFiles/_search)' -d  
> '{"query":{"field":{"file" : "Account"}},"highlight":{"fields":  
> {"file": {}}}}'
> 
> However when I try to query via the parent type "content" using a  
> has\_child query, I get the search results but I don't get the  
> highlight elements:
> 
> curl -XGET '[http://localhost:9201/foo\_acme/content/\_search](http://localhost:9201/foo_acme/content/_search)' -d  
> '{"query": {"has\_child":{"type":"contentFiles", "query":{"field":  
> {"file" : "Account"}},"highlight":{"fields":{"file":{}}}}}}'
> 
> I'm using elasticsearch version 0.16.2.
> 
> For completeness, here is my mapping for the contentFiles type, but I  
> think the mapping is ok, since my first query works:  
> {  
> "contentFiles": {  
> "\_source" : {  
> "enabled" : false  
> },  
> "\_parent": {  
> "type" : "content"  
> },  
> "properties" : {  
> "file" : {  
> "type" : "attachment",  
> "fields" : {  
> "file" : {"store" : "yes",  
> "term\_vector" : "with\_positions\_offsets"}  
> }  
> }  
> }  
> }  
> }
> 
> Thanks!  
> Lar

---

<div class="post-metadata">

### Author: ![Lar\_Mader](https://avatars.discourse-cdn.com/v4/letter/l/a6a055/32.png) [@Lar\_Mader](https://discuss.elastic.co/u/Lar_Mader)
#### Post date: [June 16, 2011, 11:43pm UTC](https://discuss.elastic.co/t/problem-with-highlighting-in-has-child-query/4633/3 "2011-06-16T23:43:23Z")

</div>

Ok, thank you for the info!

Is this a feature that could be supported in the future? We have a  
monstrous query that goes against the parent and child docs, and it  
would be very convenient if it could do the highlighting in the  
has\_child part as well.

Cheers,  
Lar

---

<div class="post-metadata">

### Author: ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)
#### Post date: [June 17, 2011, 4:29pm UTC](https://discuss.elastic.co/t/problem-with-highlighting-in-has-child-query/4633/4 "2011-06-17T16:29:26Z")

</div>

Good question... . Nothing planned, mainly since implementation wise its quite heavy to do it (if implemented). Need to spend some time thinking about it properly.

On Friday, June 17, 2011 at 2:43 AM, lmader wrote:

> Ok, thank you for the info!
> 
> Is this a feature that could be supported in the future? We have a  
> monstrous query that goes against the parent and child docs, and it  
> would be very convenient if it could do the highlighting in the  
> has\_child part as well.
> 
> Cheers,  
> Lar

---

<div class="post-metadata">

### Author: ![rnc000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rnc000/32/1978_2.png) [@rnc000](https://discuss.elastic.co/u/rnc000)
#### Post date: [November 16, 2013, 1:40pm UTC](https://discuss.elastic.co/t/problem-with-highlighting-in-has-child-query/4633/5 "2013-11-16T13:40:02Z")

</div>

Hi. Has this been implemented or is there any workaround? As my documents and subdocuments are really big, I'd really like to avoid nested objects/queries.

Thanks!

---

<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, 2:06am UTC](https://discuss.elastic.co/t/problem-with-highlighting-in-has-child-query/4633/6 "2017-07-06T02:06:37Z")

</div>


