# Highlighting html text

**URL:** <https://discuss.elastic.co/t/highlighting-html-text/8247>\
**Category:** Elasticsearch\
**Created:** [June 28, 2012, 7:21am UTC](https://discuss.elastic.co/t/highlighting-html-text/8247 "2012-06-28T07:21:02Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![sahlex](https://avatars.discourse-cdn.com/v4/letter/s/e47774/32.png) [@sahlex](https://discuss.elastic.co/u/sahlex)\
**Post date:** [June 28, 2012, 7:21am UTC](https://discuss.elastic.co/t/highlighting-html-text/8247/1 "2012-06-28T07:21:02Z")

</div>

Hi all.

I have to show highlighted fragments out of html documents in a live search  
element on a web page.

How do I achieve this?

When analysing the documents, I strip\_html filter the html tags out of the  
indexed document but the original source still contains the tags. This is  
by intention, because I don't want to lose the tags, as I want to display  
the full html text when user clicks on search hit.

But when _displaying_ the highlighted fragment, the tags should be filtered  
out of the fragment, except the highlighting tags.

Please help!

---

<div class="post-metadata">

**Author:** ![vineeth\_mohan](https://avatars.discourse-cdn.com/v4/letter/v/bc79bd/32.png) [@vineeth\_mohan](https://discuss.elastic.co/u/vineeth_mohan)\
**Post date:** [June 28, 2012, 9:02am UTC](https://discuss.elastic.co/t/highlighting-html-text/8247/2 "2012-06-28T09:02:20Z")

</div>

I had discussed this with Shay.  
Seems there is no clean way out.  
I remove the tags ( partial tags too) out of the highlighted text.

Thanks  
Vineeth

On Thu, Jun 28, 2012 at 12:51 PM, sahlex [alex.sahler@gmx.net](mailto:alex.sahler@gmx.net) wrote:

> Hi all.
> 
> I have to show highlighted fragments out of html documents in a live  
> search element on a web page.
> 
> How do I achieve this?
> 
> When analysing the documents, I strip\_html filter the html tags out of the  
> indexed document but the original source still contains the tags. This is  
> by intention, because I don't want to lose the tags, as I want to display  
> the full html text when user clicks on search hit.
> 
> But when _displaying_ the highlighted fragment, the tags should be  
> filtered out of the fragment, except the highlighting tags.
> 
> Please help!

---

<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, 3:22am UTC](https://discuss.elastic.co/t/highlighting-html-text/8247/3 "2017-07-06T03:22:12Z")

</div>


