简体   繁体   English

MySQL到Solr导入

[英]MySQL to Solr import

I want to index my MySQL db table with solr. 我想用solr索引我的MySQL数据库表。 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: 我可以在http://localhost:8983/solr/admin/dataimport.jsp?handler=/dataimport页面上看到获取的查询结果,但是对于获取的每一行,我在服务器端都遇到这些错误:

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.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: 这是我添加到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: 这是我在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> 

The error says the document you're trying to add through the DataImportHandler doesn't contain the id field, which is required. 该错误表明您尝试通过DataImportHandler添加的DataImportHandler不包含id字段,这是必填字段。 Your query doesn't return an id column, or you're not mapping it correctly within your import handler configuration. 您的查询没有返回id列,或者您没有在导入处理程序配置中正确映射它。

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. 从您添加的配置中,您的eno字段看起来像是uniqueKey,只要您的select *始终返回它,它就应该起作用。 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. 该错误表明您已按要求配置了id字段:您应该将其从架构中删除,或者如果需要将其用于其他目的,则将其设置为可选。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM