title: Solr: Document missing required uniqueKey error despite present field
body: <p>I'm working with Solr 4.3
  I have a set up with two Solr Cores: <code>userCore</code> and <code>mainCore</code></p>
  
  <p><code>userCore</code> has its own <code>schema.xml</code> and <code>solrconfig.xml</code> and is hosted on <code>localhost:8983</code>.</p>
  
  <p><code>mainCore</code> has its own different <code>schema</code> and <code>solrconfig</code>, and has a<code>SolrCloud</code> set up with one shard running at <code>localhost:8080</code>, the other at <code>localhost:7574</code></p>
  
  <p>I post documents to a <code>userToMain</code> update chain defined in <code>userCore</code>, which indexes the document and then forwards it on to another update chain in <code>mainCore</code>. Documents are processed here and indexed into <code>mainCore</code>, and then we're done.</p>
  
  <p><strong>All this worked well until distributed search got involved</strong>: 
  Documents got indexed successfully as I could tell by querying the indeces of the different cores and shards via Luke. However, distributed Solr query wasn't working for this set up because, as it turns otu, my <code>mainCore</code> (i.e. the one with SolrCloud set up) did not have a <code>uniqueKey</code> defined. </p>
  
  <p>So I tried to remedy this. I'd already had the following field in the <code>mainCore</code> schema:</p>
  
  <p><code>&lt;field name="doc-id" type="string" indexed="true" stored="true" multiValued="false" required="true"/&gt;</code>  </p>
  
  <p>I wanted this to be used as uniqueKey by specifying in the schema:</p>
  
  <p><code>&lt;uniqueKey&gt;doc-id&lt;/uniqueKey&gt;</code></p>
  
  <p>Now when I post a document to <code>userCore</code> via</p>
  
  <pre><code>`java -Durl=http://localhost:8983/solr/userCore/update?update.chain=userToCoref -jar \
  $(SOLR_HOME)/example/exampledocs/post.jar example/examplesdocs/test_doc0.xml`
  </code></pre>
  
  <p>I receive the error </p>
  
  <p><code>Document is missing mandatory uniqueKey field: doc-id</code> </p>
  
  <p>not only in <code>mainCore</code>, in whose schema <code>uniqueKey</code> is actually defined, <strong>but also in</strong> <code>userCore</code> in whose schema there is <strong>not even a mention of a</strong> <code>uniqueKey</code>!</p>
  
  <p>Specifically, <strong>here's part of the error for</strong> <code>mainCore</code>:</p>
  
  <pre><code>127578 [qtp1733460569-16] INFO  org.apache.solr.update.processor.LogUpdateProcessor  – [corefCore] webapp=/solr path=/update params={wt=javabin&amp;version=2} {} 0 619
  127579 [qtp1733460569-16] ERROR org.apache.solr.core.SolrCore  – org.apache.solr.common.SolrException: Document is missing mandatory uniqueKey field: doc-id
  at org.apache.solr.update.AddUpdateCommand.getHashableId(AddUpdateCommand.java:132)
  at org.apache.solr.update.processor.DistributedUpdateProcessor.processAdd(DistributedUpdateProcessor.java:389)
  at org.apache.solr.update.processor.LogUpdateProcessor.processAdd(LogUpdateProcessorFactory.java:100)
  at org.apache.solr.update.processor.UpdateRequestProcessor.processAdd(UpdateRequestProcessor.java:51)
  </code></pre>
  
  <p><strong>Part of Error for userCore</strong>:</p>
  
  <pre><code>135506 [qtp1733460569-19] INFO  org.apache.solr.update.processor.LogUpdateProcessor  – [userCore] webapp=/solr path=/update params={update.chain=userToCoref} {} 0 628
  135507 [qtp1733460569-19] ERROR org.apache.solr.core.SolrCore  – org.apache.solr.client.solrj.impl.HttpSolrServer$RemoteSolrException: Document is missing mandatory uniqueKey field: doc-id
  at org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:402)
  at org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:180)
  at org.apache.solr.client.solrj.request.AbstractUpdateRequest.process(AbstractUpdateRequest.java:117)
  at org.apache.solr.client.solrj.SolrServer.add(SolrServer.java:116)
  at org.apache.solr.client.solrj.SolrServer.add(SolrServer.java:102)
  </code></pre>
  
  <p><strong>In summary, what baffles me is two-fold</strong>:</p>
  
  <p>1) Why, when I actually have <code>doc-id</code> field defined in my mainCore schema, when I point <code>uniqueKey</code> to it, and when it <em>does</em> get indexed under all other circumstances, does Solr complain that <code>Document is missing mandatory uniqueKey field:doc-id</code> ???</p>
  
  <p>2) Even if something is indeed wrong with mainCore in terms of this field, why oh why is userCore also seem to be complaining about this? They are on totally different servers, with totally different configs. All userCore does is post documents it receives to mainCore, as specified by the URL of this mainCore.</p>
  
  <p>Any help would be much appreciated!</p>
  
  <p><strong>EDIT</strong>: I wanted to provide some answers to the comments.
  The original document posted to <code>userCore</code>, test_doc0.xml, looks like this:</p>
  
  <p><code>&lt;add&gt;&lt;doc&gt;</code></p>
  
  <p><code>&lt;field name="docid"&gt;docid0&lt;/field&gt;</code></p>
  
  <p><code>&lt;field name="coref_input"&gt;Bill Clinton was the 42nd president.  Clinton's wife Hillary is
  currently Secretary of State.  Hillary Clinton ran for president
  unsuccessfully.&lt;/field&gt;</code></p>
  
  <p><code>&lt;/doc&gt;&lt;/add&gt;</code></p>
  
  <p>After it gets indexed to <code>userCore</code>, it gets sent to <code>mainCore</code> for processing via this particular logic in the relevant updateRequestProcessor, <code>userToMainUpdateRequestProcessor.java</code>:</p>
  
  <pre><code>public void processAdd(AddUpdateCommand cmd) throws IOException {
      SolrInputDocument userDoc = cmd.getSolrInputDocument();
  
      SolrInputField userInputField = userDoc.getField(inputField);
      if (userInputField != null) {
          SolrInputField userDocIdField = userDoc.getField(docIdField);
          if (userDocIdField == null || userDocIdField.getValueCount() &gt; 1) {
              throw new RuntimeException(docIdField + " must be present and single-valued");
          }
      }
  
      SolrResponse response;
      try {
          mainServer.add(userDoc);
          mainServer.commit();
      } catch (SolrServerException e) {
          throw new RuntimeException(e);
      }
  
      super.processAdd(cmd);
  }
  </code></pre>
  
  <p>where <code>mainServer</code> is defined in <code>UserToMainUpdateRequestProcessorFactory.java</code> as: </p>
  
  <p><code>mainServer = new HttpServer("http://localhost:8080/solr/mainCore");</code></p>
  
  <p>Thus <code>userCore</code> posts a doc to <code>mainCore</code>, and <code>mainCore</code> does a bunch of processing to produce some more fields like this (I can't include full document): </p>
  
  <p>Name_Data: hillary clinton<br>
  Name_FullnameOverrides: enghillary clinton<br>
  Name_CompletedData: hillary clinton<br>
  name-token-count: 2<br>
  doc-id: docid0<br>
  doc-language: eng<br>
  indoc-chain-id: 5<br>
  longest-mention: Hillary Clinton<br>
  confidence: 0.9443013649773926  </p>