title: How to do mapping while indexing in elasticsearch
body: <p>I am using <code>ElasticSearch</code> in a website where i index data from <code>MongoDB</code>.</p>
  
  <pre><code>def postToEs(self):
      """
      put data to the elasticsearch
      """
      es = Elasticsearch()
      cursor = self.getMongoData()
      for document in cursor:
          esdoc={}
          esdoc["category"] = document.get("category")
          esdoc["description"] = document.get("description")
          esdoc["title"] = document.get("title")
          esdoc["link"] = document.get("link")
          esdoc["state"] = document.get("state")
          esdoc_id = esdoc["link"]
          es.index(
              index = 'news',
              doc_type = 'allnews',
              id = esdoc_id,
              body = json.dumps(esdoc)
          )
  </code></pre>
  
  <p>This worked good. But currently I have to search in the <code>state</code> field for an exact match in <code>elasticsearch</code>. Currently if I search for entries for <code>New York</code> it also gives result of <code>New Hampshire</code>. I have found <a href="https://stackoverflow.com/questions/18598418/elastic-search-exact-match">This link</a> and saw elasticsearch documentation that I need to add <code>mapping</code> on the data. My question is how do I add a mapping on the data in the current scenario? or is there any better way of doing it?</p>