# Highlighting filtred query

**URL:** <https://discuss.elastic.co/t/highlighting-filtred-query/31716>\
**Category:** Elasticsearch\
**Created:** [October 6, 2015, 4:30pm UTC](https://discuss.elastic.co/t/highlighting-filtred-query/31716 "2015-10-06T16:30:14Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kyatim](https://avatars.discourse-cdn.com/v4/letter/k/a183cd/32.png) [@kyatim](https://discuss.elastic.co/u/kyatim)\
**Post date:** [October 6, 2015, 4:30pm UTC](https://discuss.elastic.co/t/highlighting-filtred-query/31716/1 "2015-10-06T16:30:14Z")

</div>

Hi,

How should I transform this query to get highlighti field in response.

Thank you!

{  
"query" : {  
"filtered" : {  
"query" : {  
"match\_all" : { }  
},  
"filter" : {  
"and" : {  
"filters" : [ {  
"or" : {  
"filters" : [ {  
"query" : {  
"match" : {  
"A.Memberid" : {  
"query" : "Rec01",  
"type" : "boolean"  
}  
}  
}  
}, {  
"query" : {  
"match" : {  
"A.Memberid" : {  
"query" : "Rec02",  
"type" : "boolean"  
}  
}  
}  
}  
} ]  
}  
}, {  
"query" : {  
"match" : {  
"A.Permname" : {  
"query" : "VIEW",  
"type" : "boolean"  
}  
}  
}  
}, {  
"and" : {  
"filters" : [ {  
"terms" : {  
"Content" : ["myname"]  
}  
} ]  
}  
} ]  
}  
}  
}  
},  
"\_source" : false,  
"fields" : ["Id", "Code", "Date"],  
"highlight" : {  
"fields" : {  
"Content" : {  
"fragment\_size" : 150,  
"number\_of\_fragments" : 3,  
"matched\_fields" : ["Content"]  
}  
}  
}  
}

---

<div class="post-metadata">

**Author:** ![nik9000](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/nik9000/32/44947_2.png) [@nik9000](https://discuss.elastic.co/u/nik9000)\
**Post date:** [October 6, 2015, 4:45pm UTC](https://discuss.elastic.co/t/highlighting-filtred-query/31716/2 "2015-10-06T16:45:06Z")

</div>

First: use ``` above and below the json to format it as code so the query is readable.

> [@kyatim](#):
>
> How should I transform this query to get highlighti field in response.

> [@kyatim](#):
>
> ```auto
> "matched_fields" : ["Content"]
> 
> ```

Never use `matched_fields` when you would just put the name of the field in there - its slower. It shouldn't hurt anything though.

Sometimes elasticsearch needs help extracting the right terms from the query for highlighting. Its a symptom of a deeper problem. Anyway, you can generally work around it by using `highlight_query`. In this case I'd try sending a terms query that is a copy of your terms filter on `Content`.

---

<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:46pm UTC](https://discuss.elastic.co/t/highlighting-filtred-query/31716/3 "2017-07-05T23:46:31Z")

</div>


