# Return highlighted fragments and full highlighted field in same request

**URL:** https://discuss.elastic.co/t/return-highlighted-fragments-and-full-highlighted-field-in-same-request/47047
**Category:** Elasticsearch
**Created:** [April 11, 2016, 9:31pm UTC](https://discuss.elastic.co/t/return-highlighted-fragments-and-full-highlighted-field-in-same-request/47047 "2016-04-11T21:31:42Z")
**Posts on this page:** 4
**Page:** 1

<div class="post-metadata">

### Author: ![patrick.gerzanics](https://avatars.discourse-cdn.com/v4/letter/p/edb3f5/32.png) [@patrick.gerzanics](https://discuss.elastic.co/u/patrick.gerzanics)
#### Post date: [April 11, 2016, 9:31pm UTC](https://discuss.elastic.co/t/return-highlighted-fragments-and-full-highlighted-field-in-same-request/47047/1 "2016-04-11T21:31:42Z")

</div>

My apologies in advance as I'm new to ES. This is kind of a strange use-case, but we have a large text field that we would like to do 2 things with:

1. Show the first X chars of the body text with any search results highlighted
2. Show the first Y highlights/fragments of the body text with search results highlighted

My goal is to do this all in one search, but I can't find a way to get the same field back with different highlighting parameters. I was thinking maybe if I had some way to create an alias on the field then I could refer to it in the highlights section but I couldn't find a way to do that either.

We can simply store the first X chars of the document as a separate field to work around the issue, but the developer handing ingestion would prefer to avoid that.

Any thoughts would be much appreciated.

---

<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: [April 11, 2016, 9:47pm UTC](https://discuss.elastic.co/t/return-highlighted-fragments-and-full-highlighted-field-in-same-request/47047/2 "2016-04-11T21:47:27Z")

</div>

> [@patrick.gerzanics](#):
>
> We can simply store the first X chars of the document as a separate field to work around the issue, but the developer handing ingestion would prefer to avoid that.

Right. So if you were willing to hack on highlighting you could implement this but Elasticsearch doesn't have a feature like that. It has "return the first x characters if nothing in this field matched" (`no_match_size`) and it has "return the x best fragments" (that is highlighting's default).

You can get something kindof like what you want with the `limit` token filter: [Limit token count token filter | Elasticsearch Guide [8.11] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-limit-token-count-tokenfilter.html)

You'd make one field but analyze it twice, once limiting the token count to 1000 or something suitably small and the other time without the limit. Then you'd highlight against both of the names. Note: this'd get you the first 1000 _words_ not the first 1000 characters. But words are better than characters any way!

---

<div class="post-metadata">

### Author: ![patrick.gerzanics](https://avatars.discourse-cdn.com/v4/letter/p/edb3f5/32.png) [@patrick.gerzanics](https://discuss.elastic.co/u/patrick.gerzanics)
#### Post date: [April 12, 2016, 6:37am UTC](https://discuss.elastic.co/t/return-highlighted-fragments-and-full-highlighted-field-in-same-request/47047/3 "2016-04-12T06:37:52Z")

</div>

Thanks for the reply. I will take a look at that limit method as that sounds like it might suit our needs.

Cheers.

---

<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:00pm UTC](https://discuss.elastic.co/t/return-highlighted-fragments-and-full-highlighted-field-in-same-request/47047/4 "2017-07-05T23:00:24Z")

</div>


