title: Indexing multiple documents
body: <p>I encounter errors while trying to index multiple documents in <code>solr</code> with <code>spark-streaming</code> using <code>solrj</code>. Each record I parse and index, each <code>micro-batch</code>.</p>
  
  <p>In the code below, the first method (tagged) functions as expected. The second method (tagged) does not do anything, it does not event fail.</p>
  
  <p>In the first option, I index a record for each partition; useless, but functional.
  In the second method, I convert each element of my partitions into a document and then try to index each of them, but fail: no records are showing in the collection.</p>
  
  <p>I use <code>solrj 4.10</code> and <code>spark-2.2.1</code>.</p>
  
  <pre class="lang-scala prettyprint-override"><code>//method 1
  myDStream.foreachRDD { rdd =&gt; rdd.foreachPartition { records =&gt;
  
    val solrServer = new HttpSolrServer(collectionUrl)
  
    val document = new SolrInputDocument()
    document.addField("key", "someValue")
    ...
  
    solrServer.add(document)
    solrServer.commit()
  }}
  </code></pre>
  
  <pre class="lang-scala prettyprint-override"><code>//method 2
  myDStream.foreachRDD { rdd =&gt; rdd.foreachPartition { records =&gt;
  
    val solrServer = new HttpSolrServer(collectionUrl)
  
    records.map { record =&gt;
  
      val document = new SolrInputDocument()
      document.addField("key", record.key)
      ...
  
      solrServer.add(document)
      solrServer.commit()
    }
  }}
  </code></pre>
  
  <p>I would like to understand why the second method does not work and find a solution to multiple documents indexing.</p>