大家好,我想使用solr对我的MySQL数据库表进行索引。我已经安装了必要的Java组件/适配器等。我的数据库名为“test_db”,其中的表名为“table_tb”。该表包含两列(字段)
-第1个字段名为“ID”,是自增的主键整数 -第2个字段名为“COLA”,是文本
该表有两行记录,ID = 1和ID = 2,每行都对应第二列中的一些文本。我已经设置了以下配置文件(它们位于正确的目录中):
data-config.xml
<dataConfig>
<dataSource type="JdbcDataSource"
driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost/test_db"
user="username"
password="db_pwd"/>
<document name="doc">
<entity name="test_tb" query="select ID from test_tb">
<field column="ID" name="ID" />
<field column="COLA" name="COLA" />
</entity>
</document>
</dataConfig>
solrconfig.xml
<requestHandler name="/dataimport" class="org.apache.solr.handler.dataimport.DataImportHandler">
<lst name="defaults">
<str name="config">data-config.xml</str>
</lst>
</requestHandler>
schema.xml
<fields>
<field name="ID" type="int" indexed="true" stored="true" required="true"/>
<field name="COLA" type="string" indexed="true" stored="true" required="true"/>
</fields>
<uniqueKey>ID</uniqueKey>
当我在浏览器中输入
"[URL]:8983/solr/dataimport?command=full-import"
,我会得到以下输出:(1) 浏览器输出(xml)
<response>
−
<lst name="responseHeader">
<int name="status">0</int>
<int name="QTime">1</int>
</lst>
−
<lst name="initArgs">
−
<lst name="defaults">
<str name="config">data-config.xml</str>
</lst>
</lst>
<str name="command">full-import</str>
<str name="status">idle</str>
<str name="importResponse"/>
−
<lst name="statusMessages">
<str name="Total Requests made to DataSource">1</str>
<str name="Total Rows Fetched">2</str>
<str name="Total Documents Skipped">0</str>
<str name="Full Dump Started">2010-08-03 16:15:51</str>
−
<str name="">
Indexing completed. Added/Updated: 0 documents. Deleted 0 documents.
</str>
<str name="Committed">2010-08-03 16:15:51</str>
<str name="Optimized">2010-08-03 16:15:51</str>
<str name="Total Documents Processed">0</str>
<str name="Total Documents Failed">2</str>
<str name="Time taken ">0:0:0.32</str>
</lst>
−
<str name="WARNING">
This response format is experimental. It is likely to change in the future.
</str>
</response>
建议已读取2条记录但未索引
服务器端输出
WARNING: Error creating document : SolrInputDocument[{ID=ID(1.0)={1}}]
org.apache.solr.common.SolrException: Document [null] missing required field: id
WARNING: Error creating document : SolrInputDocument[{ID=ID(1.0)={2}}]
org.apache.solr.common.SolrException: Document [null] missing required field: id
有人知道我做错了什么吗?
提前感谢任何帮助!!!