# Highlighter trim a field, why?

**URL:** https://discuss.elastic.co/t/highlighter-trim-a-field-why/36779
**Category:** Elasticsearch
**Created:** [December 9, 2015, 6:00pm UTC](https://discuss.elastic.co/t/highlighter-trim-a-field-why/36779 "2015-12-09T18:00:08Z")
**Posts on this page:** 7
**Page:** 1

<div class="post-metadata">

### Author: ![ebuildy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ebuildy/32/6070_2.png) [@ebuildy](https://discuss.elastic.co/u/ebuildy)
#### Post date: [December 9, 2015, 6:00pm UTC](https://discuss.elastic.co/t/highlighter-trim-a-field-why/36779/1 "2015-12-09T18:00:08Z")

</div>

I use default mapping:

```
PUT /tom/test/1
{
   "title" : "tom",
   "url" : "http://www.fetedelascience.fr/",
   "url2" : "http://www.fetedelascience.fr/3"
}

```

> POST /tom/\_search  
> {  
> "query": {  
> "match": {  
> "title": "tom"  
> }  
> },  
> "highlight": {  
> "no\_match\_size":155,  
> "fields": {  
> "url" : {},  
> "url2" : {}  
> }  
> }  
> }

Gives me:

```
{
    "_index": "tom",
    "_type": "test",
    "_id": "1",
    "_score": 0.30685282,
    "_source": {
       "title": "tom",
       "url": "http://www.fetedelascience.fr/",
       "url2": "http://www.fetedelascience.fr/3"
    },
    "highlight": {
       "url2": [
          "http://www.fetedelascience.fr/3"
       ],
       "url": [
          "http://www.fetedelascience.fr"
       ]
    }
 }

```

Why the last slash of URL has disappeared?

---

<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: [December 9, 2015, 7:38pm UTC](https://discuss.elastic.co/t/highlighter-trim-a-field-why/36779/2 "2015-12-09T19:38:31Z")

</div>

> [@ebuildy](#):
>
> Why the last slash of URL has disappeared?

Weird. Its just how the no\_match segmenter works in the plain highlighter. It just grabs text ending at the last token before the end of the text. I wrote this many years ago to simulate how the plain highlighter does segmentation when it finds hits but it looks like its wrong. This is a bug but I don't think it'll be too high on my priority list, sadly:

> <https://github.com/elastic/elasticsearch/issues/15348>
>
> I'm not sure if it also does it incorrectly for longer strings, but here is the …reproduction:
> https://discuss.elastic.co/t/highlighter-trim-a-field-why/36779

---

<div class="post-metadata">

### Author: ![ebuildy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ebuildy/32/6070_2.png) [@ebuildy](https://discuss.elastic.co/u/ebuildy)
#### Post date: [December 9, 2015, 7:53pm UTC](https://discuss.elastic.co/t/highlighter-trim-a-field-why/36779/3 "2015-12-09T19:53:27Z")

</div>

No problem, happy to find the reason at least!

This is something wrote in ES not in Lucene, here [https://github.com/elastic/elasticsearch/tree/master/core/src/main/java/org/elasticsearch/search/highlight](https://github.com/elastic/elasticsearch/tree/master/core/src/main/java/org/elasticsearch/search/highlight) ?

Do you think if I use fast\_ or posting\_ hightligther this could fix it?

Thanks you,

---

<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: [December 9, 2015, 8:25pm UTC](https://discuss.elastic.co/t/highlighter-trim-a-field-why/36779/4 "2015-12-09T20:25:01Z")

</div>

> [@ebuildy](#):
>
> This is something wrote in ES not in Lucene

Yeah, I'm aware. To varying degrees they are able to delegate down to the Lucene bits.

> [@ebuildy](#):
>
> Do you think if I use fast\_ or posting\_ hightligther this could fix it?

They all implement the process differently. You should try on the fvh, its more likely to work. The postings highlighter isn't going to do what you want unless you feed it complete sentences.

---

<div class="post-metadata">

### Author: ![ebuildy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/ebuildy/32/6070_2.png) [@ebuildy](https://discuss.elastic.co/u/ebuildy)
#### Post date: [December 9, 2015, 8:32pm UTC](https://discuss.elastic.co/t/highlighter-trim-a-field-why/36779/5 "2015-12-09T20:32:05Z")

</div>

Just curious, why not rely on Lucene highlighter?

I will test fvh tomorrow, after re-indexing my data.

thanks you

---

<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: [December 9, 2015, 9:11pm UTC](https://discuss.elastic.co/t/highlighter-trim-a-field-why/36779/6 "2015-12-09T21:11:55Z")

</div>

> [@ebuildy](#):
>
> Just curious, why not rely on Lucene highlighter?

Lucene doesn't have support for no\_match\_size. Most of the code elasticsearch has for highlighting is really just to adapt the API into Lucene's highlighters. no\_match\_size is kind of an anomaly in that its trying to implement something without upstreaming it. And I'm not 100% sure why I didn't upstream the change at the time.

---

<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:32pm UTC](https://discuss.elastic.co/t/highlighter-trim-a-field-why/36779/7 "2017-07-05T23:32:12Z")

</div>


