# Highlight part of a term

**URL:** <https://discuss.elastic.co/t/highlight-part-of-a-term/4004>\
**Category:** Elasticsearch\
**Created:** [March 1, 2011, 5:53pm UTC](https://discuss.elastic.co/t/highlight-part-of-a-term/4004 "2011-03-01T17:53:40Z")\
**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:53pm UTC](https://discuss.elastic.co/t/highlight-part-of-a-term/4004/1 "2011-03-01T17:53:40Z")

</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:** ![kimchy](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kimchy/32/44952_2.png) [@kimchy](https://discuss.elastic.co/u/kimchy)\
**Post date:** [March 2, 2011, 12:40am UTC](https://discuss.elastic.co/t/highlight-part-of-a-term/4004/2 "2011-03-02T00:40:24Z")

</div>

If you want to highlight only what you typed, do it on the client side.  
On Tuesday, March 1, 2011 at 7:53 PM, alheim wrote:

> 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:** ![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, 4:11am UTC](https://discuss.elastic.co/t/highlight-part-of-a-term/4004/3 "2017-07-06T04:11:07Z")

</div>


