(我已经在下面的XML中显示了它)
大家好我想用solr索引我的MySQL数据库表 . 我已经安装了必要的java组件/适配器等 . 我的数据库名为'test_db',其中的表名为'table_tb' . 该表包含2列(字段)
-Field 1称为'ID',是一个自动增量的主键整数 - 字段2称为'COLA',是文本
该表有两行(记录)ID = 1和ID = 2,其中一些文本对应于第二列 . 我已经设置了以下conf文件(它们位于正确的目录中):
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
有谁知道我做错了什么?
在此先感谢任何帮助!
3 回答
字段“id”出现在文档的其他位置 . 我评论了这一点并且有效 .
你需要有synchronized:scheme.xml和data-config.xml中的内容(字段的定义需要相同)
它应该是query =“select * from test_tb”我认为 .
如果你从test_tb执行查询select id,你只需要一列,而你想要两个 .