The html_strip character filter removes HTML tags from an input stream before tokenization. Use it when indexed text contains markup that should not affect search analysis. section 7.6 section 7.6.1
Strip headings before tokenization
POST _analyze { "text": "<h1>Where is my cheese?</h1>", "tokenizer": "standard", "char_filter": ["html_strip"] } The tags are removed first, leaving the words “Where”, “is”, “my”, and “cheese” for the standard tokenizer. section 7.6.1
Use html_strip inside a custom analyzer alongside a tokenizer and token filters. Character filters run first, so later analysis receives text without the removed markup. section 7.4 section 7.6
Preserve selected tags
Define a custom html_strip filter with an escaped_tags array when some tags must remain unparsed: "char_filter": { "my_html_strip_filter": { "type": "html_strip", "escaped_tags": ["h1"] } } With <h1>Hello,</h1> <h2>World!</h2>, the h1 tags remain while the h2 tags are stripped. section 7.6.1
Listing 7.24 Custom analyzer with filters and a tokenizer
PUT index_with_custom_analyzer { "settings": { "analysis": { "analyzer": { "custom_analyzer":{ #1 "type":"custom", #2 "char_filter":["html_strip"], #3 "tokenizer":"standard", #4 "filter":["uppercase"] #5 } } } } } #1 Specifies the custom analyzer #2 The type must be custom to let Elasticsearch know about our custom analyzer. #3 Array of character filters #4 Declares a single tokenizer (standard, in this case) #5 Token filter to uppercase incoming tokens
Inspect the complete custom analyzer configuration, including the character-filter array, standard tokenizer, and uppercase token filter. section 7.4
