0
votes

I'm developing one MVC application with implementing Solr (latest version solr-4.10.3) using SolrNet (version 0.4.0.2002). I'm newbie for Solr/SolrNet and using http://crazorsharp.blogspot.in/2010/01/full-text-search-using-solr-lucene-and.html tutorial for the practice. I'm getting following error while indexing the database table data to index using SolrNet.dll.

An exception of type 'SolrNet.Exceptions.SolrConnectionException' occurred in SolrNet.dll but was not handled in user code

Additional information: <?xml version="1.0" encoding="UTF-8"?>

<response>
<lst name="responseHeader">
   <int name="status">400</int>
   <int name="QTime">51</int>
</lst>
<lst name="error">
    <str name="msg">Document is missing mandatory uniqueKey field: id</str>
    <int name="code">400</int>
</lst>
</response>

schema.xml

<?xml version="1.0" encoding="UTF-8" ?>
<schema name="nopAccelerate" version="1.7">
  <types>
    <fieldType name="string" class="solr.StrField" sortMissingLast="true" omitNorms="true"/>
    <fieldType name="boolean" class="solr.BoolField" sortMissingLast="true" />
    <fieldType name="int" class="solr.TrieIntField" precisionStep="0" positionIncrementGap="0" omitNorms="true"/>
    <fieldType name="float" class="solr.TrieFloatField" precisionStep="0" positionIncrementGap="0"/>
    <fieldType name="date" class="solr.TrieDateField" precisionStep="6" positionIncrementGap="0"/>
    <fieldType name="text" class="solr.TextField" positionIncrementGap="100">
      <analyzer type="index">
        <tokenizer class="solr.StandardTokenizerFactory"/>
        <charFilter class="solr.HTMLStripCharFilterFactory"/>
        <charFilter class="solr.MappingCharFilterFactory" mapping="mapping-ISOLatin1Accent.txt"/>
        <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" enablePositionIncrements="true" />
        <filter class="solr.LowerCaseFilterFactory"/>
        <filter class="solr.PorterStemFilterFactory"/>
      </analyzer>
      <analyzer type="query">
        <tokenizer class="solr.StandardTokenizerFactory"/>
        <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" enablePositionIncrements="true" />
        <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
        <filter class="solr.LowerCaseFilterFactory"/>
        <filter class="solr.PorterStemFilterFactory"/>
      </analyzer>
    </fieldType>
    <fieldType name="textSpell" class="solr.TextField" positionIncrementGap="100">
      <analyzer type="index">
        <tokenizer class="solr.StandardTokenizerFactory"/>
        <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" enablePositionIncrements="true" />
        <filter class="solr.LowerCaseFilterFactory"/>
      </analyzer>
      <analyzer type="query">
        <tokenizer class="solr.StandardTokenizerFactory"/>
        <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" enablePositionIncrements="true" />
        <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
        <filter class="solr.LowerCaseFilterFactory"/>
      </analyzer>
    </fieldType>
    <fieldType name="long" class="solr.TrieLongField" precisionStep="0" positionIncrementGap="0"/>
    <fieldType name="nGramtext" class="solr.TextField" positionIncrementGap="100">
      <analyzer type="index">
        <tokenizer class="solr.StandardTokenizerFactory"/>
        <charFilter class="solr.HTMLStripCharFilterFactory"/>
        <charFilter class="solr.MappingCharFilterFactory" mapping="mapping-ISOLatin1Accent.txt"/>
        <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" enablePositionIncrements="true" />
        <filter class="solr.LowerCaseFilterFactory"/>
        <filter class="solr.EdgeNGramFilterFactory" minGramSize="3" maxGramSize="15" side="front"/>
        <filter class="solr.EdgeNGramFilterFactory" minGramSize="3" maxGramSize="15" side="back"/>
        <filter class="solr.PorterStemFilterFactory"/>
      </analyzer>
      <analyzer type="query">
        <tokenizer class="solr.StandardTokenizerFactory"/>
        <filter class="solr.StopFilterFactory" ignoreCase="true" words="stopwords.txt" enablePositionIncrements="true" />
        <filter class="solr.SynonymFilterFactory" synonyms="synonyms.txt" ignoreCase="true" expand="true"/>
        <filter class="solr.LowerCaseFilterFactory"/>
        <filter class="solr.PorterStemFilterFactory"/>
      </analyzer>
    </fieldType>
  </types>
  <fields>  
    <field name="Id" type="int" indexed="true" stored="true" required="true" />
    <field name="FirstName" type="string" indexed="true" stored="true" required="false" />
    <field name="MiddleName" type="string" indexed="true" stored="false" required="false" />
    <field name="LastName" type="string" indexed="true" stored="false" required="false" />
    <field name="EmailId" type="string" indexed="true" stored="false" required="false" />
    <field name="MobileNumber" type="string" indexed="true" stored="false" required="false" /> 
    <field name="_version_" type="long" indexed="true" stored="true"/>
  </fields>
  <uniqueKey>Id</uniqueKey>
  <defaultSearchField>FirstName</defaultSearchField>
  <solrQueryParser defaultOperator="OR"/>
</schema>

core.properties

#Written by CorePropertiesLocator
#Wed Jan 21 10:30:51 IST 2015
name=mytestcore
config=D\:\\SolrTest\\mytestcore\\conf\\solrconfig.xml
schema=D\:\\SolrTest\\mytestcore\\conf\\schema.xml
dataDir=D\:\\SolrTest\\mytestcore\\data

EmpSolr.cs Mapper class between Solr, SQL & SolrNet

public class EmpSolr
{
    [SolrUniqueKey("Id")]
    public int Id { get; set; }

    [SolrField("FirstName")]
    public string FirstName { get; set; }

    [SolrField("MiddleName")]
    public string MiddleName { get; set; }

    [SolrField("LastName")]
    public string LastName { get; set; }

    [SolrField("EmailId")]
    public string EmailId { get; set; }

    [SolrField("MobileNumber")]
    public string MobileNumber { get; set; }
}

Indexer Class

public void IndexFiles()
{
    //Startup.Init<EmpSolr>(this.solrUrl);
    Startup.Init<EmpSolr>("http://localhost:8888/solr/#/mytestcore"); //chagned default port during installations
    var solrWorker = ServiceLocator.Current.GetInstance<ISolrOperations<EmpSolr>>();

    var employees = new SolrRepository(this.connectionString).GetEmployees();
    solrWorker.Add(employees);
    solrWorker.Commit();
}

ERROR LOG:

org.apache.solr.common.SolrException: Document is missing mandatory uniqueKey field: id
    at org.apache.solr.update.AddUpdateCommand.getIndexedId(AddUpdateCommand.java:93)
    at org.apache.solr.update.processor.DistributedUpdateProcessor.versionAdd(DistributedUpdateProcessor.java:939)
    at org.apache.solr.update.processor.DistributedUpdateProcessor.processAdd(DistributedUpdateProcessor.java:692)
    at org.apache.solr.update.processor.LogUpdateProcessor.processAdd(LogUpdateProcessorFactory.java:100)
    at org.apache.solr.handler.loader.XMLLoader.processUpdate(XMLLoader.java:247)
    at org.apache.solr.handler.loader.XMLLoader.load(XMLLoader.java:174)
    at org.apache.solr.handler.UpdateRequestHandler$1.load(UpdateRequestHandler.java:99)
    at org.apache.solr.handler.ContentStreamHandlerBase.handleRequestBody(ContentStreamHandlerBase.java:74)
    at org.apache.solr.handler.RequestHandlerBase.handleRequest(RequestHandlerBase.java:135)
    at org.apache.solr.core.SolrCore.execute(SolrCore.java:1976)
    at org.apache.solr.servlet.SolrDispatchFilter.execute(SolrDispatchFilter.java:777)
    at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:418)
    at org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:207)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
    at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:950)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:421)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1070)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:611)
    at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:314)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Unknown Source)
1

1 Answers

0
votes

It was my mistake. I've specified wrong URL to map with core. So, I changed

Startup.Init<EmpSolr>("http://localhost:8888/solr/#/mytestcore");

To

Startup.Init<EmpSolr>("http://localhost:8888/solr/mytestcore");

Removed extra # within URL.