title: Load data from MongoDb to Elasticsearch through python
body: <p>I have some json data loaded in MongoDb. e.g. doc1 = {"id": 1,"name": "x1"},doc2 = {"id": 2,"name": "x2"},doc3 = {"id": 3,"name": "x3"}. Now I want this data to import from MongoDb to Elasticsearch. I wrote this piece of code.</p>
  
  <p><div class="snippet" data-lang="js" data-hide="false" data-console="true" data-babel="false">
  <div class="snippet-code">
  <pre class="snippet-code-html lang-html prettyprint-override"><code>mgclient = MongoClient()
  db = mgclient['light-test']
  col = db['test']
  
  es1 = Elasticsearch()
  print ("Connected", es1.info())
  
  es1.indices.create(index='light-test', ignore=400)
  
  # Pull from mongo and dump into ES using bulk API
  actions = []
  for data in tqdm(col.find(), total=col.count()):
      data.pop('_id')
      action = {
          "_index": 'light-test',
          "_type": 'test',
          "_source": data
      }
      actions.append(action)
      print("complete")
      
  # Dump x number of objects at a time   
      if len(actions) &gt;= 100:
          deque(parallel_bulk(es1, actions), maxlen=0)
          actions = []
  
  print("done")
  
  a = es1.search(index='light-test', body={
    'query': {
      'match_all': {
       }
    }
  })
  print(a)</code></pre>
  </div>
  </div>
  </p>
  
  <p>The problem is in the query returned. The hits shows blank whereas it should had returned the json files.
  <a href="https://i.stack.imgur.com/7ljSv.png" rel="nofollow noreferrer">results</a></p>
  
  <p>Help me in importing the data from MongoDb to Elasticsearch.</p>