title: Storing HTML Documents in Elasticsearch
body: <h3>Scenario</h3>
  
  <p>I have HTML documents, let's say: emails. I want to store these on elastic search and search the plaintext of HTML emails.</p>
  
  <h3>Problem</h3>
  
  <p>Elasticsearch would index all the HTML tags and attributes, too. I don't want that. I want to search for <code>span</code> if it is a plain text, not a html element. For example <code>&lt;span&gt;span&lt;/span&gt;</code> could be a hit, but not <code>&lt;span&gt;some other content&lt;/span&gt;</code>.</p>
  
  <h3>Question</h3>
  
  <p>Would you recommend, to store a HTML stripped field and a HTML field in a document? Or should I store the HTML document on S3 and rather leave a stripped HTML version in elastic search? Does it even make sense</p>
  
  <p>I honestly don't know what happens if elastic search is indexing a HTML document, but I could imagine that it will also index divs and spans and all the attributes. These are things I totally don't search for. So: any suggestion on solving the problem here would be great!</p>
  
  <h3>What am I doing now?</h3>
  
  <p>Right now before I store a document in ES, I check if the index exists for the document type. If not, I create a collection with a given mapping. The mapping looks like this</p>
  
  <pre><code>{
      "analysis": {
          "analyzer": {
              "htmlStripAnalyzer": {
                  "type": "custom",
                  "tokenizer": "standard",
                  "filter": "standard",
                  "char_filter": [
                      "html_strip"
                  ]
              }
          }
      },
      "mappings": {
          "${type}": {
              "dynamic_templates": [
                  {
                      "_metadata": {
                          "path_match": "_metadata.*",
                          "mapping": {
                              "type": "keyword"
                          }
                      }
                  }
              ],
              "properties": {
                  "_tags": {
                      "type": "nested",
                      "dynamic": true
                  }
              }
          }
      }
  }
  </code></pre>
  
  <p><em>Warning: Ignore the existing mappings. It has nothing to do with my intentions. They are just there.</em></p>
  
  <p>I am replacing ${type} with the document type, let's say <code>emails</code>.
  <strong>What would it look like to tell ES to not index the HTML stuff?</strong></p>