user1208634
user1208634

Reputation: 11

MySQL to Solr import

I want to index my MySQL db table with solr. I can see the result fetched for query on my http://localhost:8983/solr/admin/dataimport.jsp?handler=/dataimport page, but I am getting these errors on server side for each row fetched:

WARNING: Error creating document : SolrInputDocument[{eno=eno(1.0)={3}, ename=ename(1.0)={pravin}, sal=sal(1.0)={300}}]
org.apache.solr.common.SolrException: Document [null] missing required field: id

This is my dataconfig.xml:

<dataConfig>
    <dataSource name="pravindb" driver="com.mysql.jdbc.Driver" url="jdbc:mysql://localhost:3306/pravindb" user="root" password="root" batchSize="-1" />
    <document>
        <entity name="ename" dataSource="pravindb" pk="eno" query="select* from emp">
            <field column="eno" name="eno"/> 
            <field column="ename" name="ename"/> <field column="sal" name="sal"/> 
        </entity>
     </document>
</dataConfig>

This is the code I have added to schema.xml:

<fields>
    <field name="eno" type="int" indexed="true" stored="true" required="true" />
    <field name="ename" type="text" indexed="true" stored="true" multiValued="true"/>
    <field name="sal" type="int" indexed="true" stored="true" multiValued="true"/>
</fields>
<uniqueKey>eno</uniqueKey>
<defaultSearchField>ename</defaultSearchField>

This is my request handler in solrconfig.xml:

<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
    <lst name="defaults">
        <str name="config">d:\clg/Project/Workspace/TestSolr/solr/conf/my-data-config.xml</str>
    </lst>
</requestHandler> 

Upvotes: 0

Views: 1444

Answers (1)

javanna
javanna

Reputation: 60235

The error says the document you're trying to add through the DataImportHandler doesn't contain the id field, which is required. Your query doesn't return an id column, or you're not mapping it correctly within your import handler configuration.

UPDATE
From the configuration you've added, looks like your eno field is the uniqueKey, which should work as long as your select * always returns it. The problem here is that you have more required fields in your schema that I guess you don't need. The error says you have the id field configured as required: you should remove it from your schema or make it optional if you need it for other purposes.

Upvotes: 1

Related Questions