# HTML Filter - How do I use it in a search?

**URL:** <https://discuss.elastic.co/t/html-filter-how-do-i-use-it-in-a-search/119138>\
**Category:** Elasticsearch\
**Created:** [February 8, 2018, 11:22pm UTC](https://discuss.elastic.co/t/html-filter-how-do-i-use-it-in-a-search/119138 "2018-02-08T23:22:19Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Jeffrey\_Blayney](https://avatars.discourse-cdn.com/v4/letter/j/838e76/32.png) [@Jeffrey\_Blayney](https://discuss.elastic.co/u/Jeffrey_Blayney)\
**Post date:** [February 8, 2018, 11:22pm UTC](https://discuss.elastic.co/t/html-filter-how-do-i-use-it-in-a-search/119138/1 "2018-02-08T23:22:19Z")

</div>

Hola,

I'm unsuccessfully trying to use analyzers, with HTML filters, and could use some help. I'm pretty sure I'm missing something fundamental here.

Here is my html character filter:

```
                "char_filter" : {
			"html_char_filter": {
				"type": "html_strip"
			}
		},

```

Here is my analyzer:

```
		"analyzer" : {
			"english_stem_analyzer" : {
				"tokenizer" : "standard",
				"filter" : [
					"stem_english_possessive_filter",
					"stem_english_filter",
					"lowercase",
					"english_stop_filter",
					"asciifolding"
				],
				"char_filter" : [
					"html_char_filter"
				]
			}
                }

```

I applied it to a field like so in the mapping:

```
			"content" : {
				"type": "text",
				"analyzer" : "english_stem_analyzer",
				"search_analyzer" : "english_stem_analyzer"
                        }

```

When I do a simple match all query, the content field still has html in it. (within the source)

Why?

How do I actually strip out html from the query response, or from the field as it is indexed?

Any light you could shed is very appreciated.

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [February 9, 2018, 8:21pm UTC](https://discuss.elastic.co/t/html-filter-how-do-i-use-it-in-a-search/119138/2 "2018-02-09T20:21:06Z")

</div>

What do you mean when the content field still has html in it? Are you  
saying that when you search for HTML, the document/field matches, or simply  
that the response contains HTML? If it is the latter, then the behavior is  
expected since the document source is preserved. The analysis chain will  
only modify what is actually indexed.

Since you are doing a match all, which mean no query terms, you probably  
are looking for the response to be modified. There is no good way to get  
the analyzed content back. Highlighting is the most used workaround.

---

<div class="post-metadata">

**Author:** ![Jeffrey\_Blayney](https://avatars.discourse-cdn.com/v4/letter/j/838e76/32.png) [@Jeffrey\_Blayney](https://discuss.elastic.co/u/Jeffrey_Blayney)\
**Post date:** [February 9, 2018, 11:28pm UTC](https://discuss.elastic.co/t/html-filter-how-do-i-use-it-in-a-search/119138/3 "2018-02-09T23:28:26Z")

</div>

The response contains HTML in the \_source.content field.

I'm using nested bool (should) queries with multiple term and match queries in them.

Can I use highlighting to get the value of the content field back with the HTML characters stripped out of it?

Thanks for any additional context and/or information!

---

<div class="post-metadata">

**Author:** ![Jeffrey\_Blayney](https://avatars.discourse-cdn.com/v4/letter/j/838e76/32.png) [@Jeffrey\_Blayney](https://discuss.elastic.co/u/Jeffrey_Blayney)\
**Post date:** [February 13, 2018, 5:54pm UTC](https://discuss.elastic.co/t/html-filter-how-do-i-use-it-in-a-search/119138/4 "2018-02-13T17:54:53Z")

</div>

Ping ^^

---

<div class="post-metadata">

**Author:** ![Ivan](https://avatars.discourse-cdn.com/v4/letter/i/df788c/32.png) [@Ivan](https://discuss.elastic.co/u/Ivan)\
**Post date:** [February 16, 2018, 1:23am UTC](https://discuss.elastic.co/t/html-filter-how-do-i-use-it-in-a-search/119138/5 "2018-02-16T01:23:43Z")

</div>

I have never used highlighting to return analyzed text, but that is what  
you should do. Never responded back since I was hoping others would chime  
in. An easy way to find out is to try it yourself!

I find it easier to index what I what and not have Elasticsearch do any  
data munging.

---

<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:** [March 16, 2018, 1:24am UTC](https://discuss.elastic.co/t/html-filter-how-do-i-use-it-in-a-search/119138/6 "2018-03-16T01:24:06Z")

</div>

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