# Highlighting part of a term

**URL:** <https://discuss.elastic.co/t/highlighting-part-of-a-term/4003>\
**Category:** Elasticsearch\
**Created:** [March 1, 2011, 5:47pm UTC](https://discuss.elastic.co/t/highlighting-part-of-a-term/4003 "2011-03-01T17:47:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Alexandre\_Heimburger](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/alexandre_heimburger/32/2941_2.png) [@Alexandre\_Heimburger](https://discuss.elastic.co/u/Alexandre_Heimburger)\
**Post date:** [March 1, 2011, 5:47pm UTC](https://discuss.elastic.co/t/highlighting-part-of-a-term/4003/1 "2011-03-01T17:47:49Z")

</div>

Hi,

I'm still working on a fast highlighted autocomplete.

Imagine that I query 'andr'

'Alexandre' and 'Andre' are matching but both terms are fully highlighted. I  
would like to hightlight only the letter I typed.

Here is my mapping :

{  
2 "usr" : {  
3 "properties" : {  
4 "title" : {  
5 "type" : "string",  
6 "term\_vector" : "with\_positions\_offsets"

7 }  
8 }  
9 }  
10 }  
11 }

Here is the query :

array('query'=\>array('bool'=\> array(  
'must' =\>  
array("query\_string"=\>array('default\_field'=\>"title",  
'default\_operator'=\>'AND', 'query'=\>"_$str_")),  
'minimum\_number\_should\_match'=\> 1,  
'boost' =\> 1.0  
)  
),  
'highlight' =\>  
array('fields'=\>array('title'=\>array('fragment\_size'=\>150,'number\_of\_fragments'=\>3)))  
);

Any clue ?

Thanks

---

<div class="post-metadata">

**Author:** ![ilia-valchenko](https://avatars.discourse-cdn.com/v4/letter/i/b9bd4f/32.png) [@ilia-valchenko](https://discuss.elastic.co/u/ilia-valchenko)\
**Post date:** [February 9, 2017, 1:27pm UTC](https://discuss.elastic.co/t/highlighting-part-of-a-term/4003/2 "2017-02-09T13:27:50Z")

</div>

I think you could try to use nGram analyzer and custom tokenizer. I found [answer](http://stackoverflow.com/questions/21310610/highlighting-part-of-word-in-elasticsearch) on stackoverflow. I hope it will help you.

---

<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, 10:03pm UTC](https://discuss.elastic.co/t/highlighting-part-of-a-term/4003/3 "2017-07-05T22:03:26Z")

</div>


