# Highlighting - limit number of highlights across fields

**URL:** <https://discuss.elastic.co/t/highlighting-limit-number-of-highlights-across-fields/15623>\
**Category:** Elasticsearch\
**Created:** [February 5, 2014, 4:38pm UTC](https://discuss.elastic.co/t/highlighting-limit-number-of-highlights-across-fields/15623 "2014-02-05T16:38:33Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michael\_Stringer](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/michael_stringer/32/1822_2.png) [@Michael\_Stringer](https://discuss.elastic.co/u/Michael_Stringer)\
**Post date:** [February 5, 2014, 4:38pm UTC](https://discuss.elastic.co/t/highlighting-limit-number-of-highlights-across-fields/15623/1 "2014-02-05T16:38:33Z")

</div>

Is there a way to limit the total number of highlights returned across all  
fields?

I know that you can set number\_of\_fragments in the top level settings but  
this is the same as setting it for each field (instead of limiting the  
total).

Example Query:  
{  
"query": {  
"multi\_match": {  
"query": "event",  
"fields": ["note", "subject"]  
}  
},  
"highlight": {  
"fragment\_size": 50,  
"number\_of\_fragments": 1,  
"fields": {  
"subject": {},  
"body": {}  
}  
}  
}

Example results:

{  
...  
"hits": [  
{  
"\_index": "test",  
"\_type": "emails",  
"\_id": "181",  
"\_score": 6.82249,  
"\_source": {  
"subject": "Upcoming event on the 25th July",  
"body": "We need to prepare for the upcoming event that is going to  
take place on the 25th July."  
...  
},  
"highlight": {  
"subject": [  
"Upcoming _event_ on the 25th July"  
],  
"body": [  
"We need to prepare for the upcoming _event_ that is..."  
]  
}  
}  
]  
}

What I'm after:

{  
...  
"hits": [  
{  
"\_index": "test",  
"\_type": "emails",  
"\_id": "181",  
"\_score": 6.82249,  
"\_source": {  
"subject": "Upcoming event on the 25th July",  
"body": "We need to prepare for the upcoming event that is going to  
take place on the 25th July."  
...  
},  
"highlight": {  
"body": [  
"We need to prepare for the upcoming _event_ that is..."  
]  
}  
}  
]  
}  
(note only 1 highlight is returned)

--  
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/43c1ffaa-fa7e-4104-ab29-4d057d162e77%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/43c1ffaa-fa7e-4104-ab29-4d057d162e77%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:** ![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:** [February 5, 2014, 5:04pm UTC](https://discuss.elastic.co/t/highlighting-limit-number-of-highlights-across-fields/15623/2 "2014-02-05T17:04:12Z")

</div>

No, there isn't a way to do that. Just throwing away the extra results is  
generally not a big deal unless the field is very expensive to highlight.  
I've found highlighting to be reasonably cheap most of the time.

On Wed, Feb 5, 2014 at 11:38 AM, Michael Stringer \<  
[michael.stringer@zestia.com](mailto:michael.stringer@zestia.com)\> wrote:

> Is there a way to limit the total number of highlights returned across all  
> fields?
> 
> I know that you can set number\_of\_fragments in the top level settings but  
> this is the same as setting it for each field (instead of limiting the  
> total).
> 
> Example Query:  
> {  
> "query": {  
> "multi\_match": {  
> "query": "event",  
> "fields": ["note", "subject"]  
> }  
> },  
> "highlight": {  
> "fragment\_size": 50,  
> "number\_of\_fragments": 1,  
> "fields": {  
> "subject": {},  
> "body": {}  
> }  
> }  
> }
> 
> Example results:
> 
> {  
> ...  
> "hits": [  
> {  
> "\_index": "test",  
> "\_type": "emails",  
> "\_id": "181",  
> "\_score": 6.82249,  
> "\_source": {  
> "subject": "Upcoming event on the 25th July",  
> "body": "We need to prepare for the upcoming event that is going  
> to take place on the 25th July."  
> ...  
> },  
> "highlight": {  
> "subject": [  
> "Upcoming _event_ on the 25th July"  
> ],  
> "body": [  
> "We need to prepare for the upcoming _event_ that is..."  
> ]  
> }  
> }  
> ]  
> }
> 
> What I'm after:
> 
> {  
> ...  
> "hits": [  
> {  
> "\_index": "test",  
> "\_type": "emails",  
> "\_id": "181",  
> "\_score": 6.82249,  
> "\_source": {  
> "subject": "Upcoming event on the 25th July",  
> "body": "We need to prepare for the upcoming event that is going  
> to take place on the 25th July."  
> ...  
> },  
> "highlight": {  
> "body": [  
> "We need to prepare for the upcoming _event_ that is..."  
> ]  
> }  
> }  
> ]  
> }  
> (note only 1 highlight is returned)
> 
> --  
> 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/43c1ffaa-fa7e-4104-ab29-4d057d162e77%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/43c1ffaa-fa7e-4104-ab29-4d057d162e77%40googlegroups.com)  
> .  
> For more options, visit [https://groups.google.com/groups/opt\_out](https://groups.google.com/groups/opt_out).

--  
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/CAPmjWd0YDUJphg9\_Hhmfh00ctwEz7tOHT4H0Ksi7FRaJo1nKgw%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAPmjWd0YDUJphg9_Hhmfh00ctwEz7tOHT4H0Ksi7FRaJo1nKgw%40mail.gmail.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:52am UTC](https://discuss.elastic.co/t/highlighting-limit-number-of-highlights-across-fields/15623/3 "2017-07-06T01:52:20Z")

</div>


