# Retrieve associated fields in a highlight query

**URL:** https://discuss.elastic.co/t/retrieve-associated-fields-in-a-highlight-query/15072
**Category:** Elasticsearch
**Created:** [January 1, 2014, 10:39pm UTC](https://discuss.elastic.co/t/retrieve-associated-fields-in-a-highlight-query/15072 "2014-01-01T22:39:28Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Chris\_Lees](https://avatars.discourse-cdn.com/v4/letter/c/278dde/32.png) [@Chris\_Lees](https://discuss.elastic.co/u/Chris_Lees)
#### Post date: [January 1, 2014, 10:39pm UTC](https://discuss.elastic.co/t/retrieve-associated-fields-in-a-highlight-query/15072/1 "2014-01-01T22:39:28Z")

</div>

I'm trying to get a highlight query working on an indexed JSON doc (not an  
attachment!).

Here's an example doc:

{  
...  
"file": {  
"blocks": [  
{  
"name": "1st Block",  
"fields": [  
{  
"id": "A",  
"name": "FirstField",  
"type": "String",  
"desc": "This is my first field"  
},  
...  
]  
},  
{  
"name": "2nd Block",  
"fields": [  
{  
"id": "C",  
"name": "SecondField",  
"type": "String",  
"desc": "This is my second field"  
},  
...  
]  
}  
]  
}  
}

I want to run a query which will search on the id, name or desc fields  
within a blocks.fields entry, but which returns enough information for the  
user to see the block.name too. Here's my current query which just  
highlights the matched field correctly:

{  
"query": {  
"query\_string": {  
"query": "SecondField"  
}  
},  
"highlight": {  
"fields": {  
"file.blocks.fields.id": {},  
"file.blocks.fields.name": {},  
"file.blocks.fields.desc": {}  
}  
}  
}

This returns the document and a highlight section as below:

highlight: {  
"file.blocks.fields.name" : [  
"_SecondField_"  
]  
}

What I'd really like is to get the return something which also returns:

"file.blocks.name": "2nd Block",  
"file.blocks.fields.id": "C",  
"file.blocks.fields.desc": "This is my second field"

Is this possible (without doing extra processing in my application)? Or is  
a highlight query the wrong thing to use here?

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/713cc3ea-006e-410e-88ee-3564435041e9%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/713cc3ea-006e-410e-88ee-3564435041e9%40googlegroups.com).  
For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

---

<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, 1:58am UTC](https://discuss.elastic.co/t/retrieve-associated-fields-in-a-highlight-query/15072/2 "2017-07-06T01:58:44Z")

</div>


