# Adding html\_strip filter

**URL:** <https://discuss.elastic.co/t/adding-html-strip-filter/319768>\
**Category:** Elasticsearch\
**Created:** [November 24, 2022, 3:19pm UTC](https://discuss.elastic.co/t/adding-html-strip-filter/319768 "2022-11-24T15:19:05Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![Srikanth\_V](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/srikanth_v/32/86839_2.png) [@Srikanth\_V](https://discuss.elastic.co/u/Srikanth_V)\
**Post date:** [November 24, 2022, 3:19pm UTC](https://discuss.elastic.co/t/adding-html-strip-filter/319768/1 "2022-11-24T15:19:05Z")

</div>

Hello all,

I would like to eliminate html tags when I am performing search on certain fields in elastic. Can this be achieved using `html_strip` filter? If yes, can I have an example on how to add the analyzer and the filter? Thank you

Regards,  
Sri

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [November 24, 2022, 3:32pm UTC](https://discuss.elastic.co/t/adding-html-strip-filter/319768/2 "2022-11-24T15:32:32Z")

</div>

Hi @Srikanth_V .

Maybe this [documentation](https://www.elastic.co/guide/en/elasticsearch/reference/current/analysis-htmlstrip-charfilter.html) help you.

---

<div class="post-metadata">

**Author:** ![Srikanth\_V](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/srikanth_v/32/86839_2.png) [@Srikanth\_V](https://discuss.elastic.co/u/Srikanth_V)\
**Post date:** [November 24, 2022, 4:04pm UTC](https://discuss.elastic.co/t/adding-html-strip-filter/319768/3 "2022-11-24T16:04:47Z")

</div>

Hello @RabBit_BR ,

Thanks. This looks fine. My main concern is, I don't want the field to loose the html tags, because I need them for display. I want to strip them when I search on them.

Regards,  
Sri

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [November 24, 2022, 4:13pm UTC](https://discuss.elastic.co/t/adding-html-strip-filter/319768/4 "2022-11-24T16:13:46Z")

</div>

I believe you have the same problem as this [post](https://stackoverflow.com/questions/73987981/elasticsearch-highlight-the-result-of-script-fields/74005074#74005074). In this case there are two indexed fields, one with the html text and the other with the text without html.

---

<div class="post-metadata">

**Author:** ![Srikanth\_V](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/srikanth_v/32/86839_2.png) [@Srikanth\_V](https://discuss.elastic.co/u/Srikanth_V)\
**Post date:** [November 25, 2022, 4:31pm UTC](https://discuss.elastic.co/t/adding-html-strip-filter/319768/5 "2022-11-25T16:31:07Z")

</div>

I would like to have only field. When I create my query on frontend it should be able to find documents that tags as well. For example -

If my text is - Hello 2 (superscript and subscript tags usage)  
and in my query if I write Hello 2, I would expect it to find this result

---

<div class="post-metadata">

**Author:** ![Srikanth\_V](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/srikanth_v/32/86839_2.png) [@Srikanth\_V](https://discuss.elastic.co/u/Srikanth_V)\
**Post date:** [November 29, 2022, 8:39am UTC](https://discuss.elastic.co/t/adding-html-strip-filter/319768/6 "2022-11-29T08:39:57Z")

</div>

@RabBit_BR : We were able to strip the html while searching, by modifying the mapping -  
{  
"analyzer": "custom\_my\_analyzer",  
"search\_analyzer": "default" // the default analyzer used,  
}

point to be noted - make sure the custom\_my\_analyzer inherits the filters from default

Thanks again for your 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:** [December 27, 2022, 8:40am UTC](https://discuss.elastic.co/t/adding-html-strip-filter/319768/7 "2022-12-27T08:40:55Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
