(我已将 ' 放入下面的 XML 中以使其显示)
大家好,我想用 solr 索引我的 MySQL 数据库表。我已经安装了必要的 java 组件/适配器等。我的数据库称为“test_db”,其中的表称为“table_tb”。该表包含 2 列(字段)
-字段 1 称为“ID”,是一个自动递增的主键整数 -字段 2 称为“COLA”,是文本
该表有两行(记录)ID=1 和 ID=2,每行都有一些文本对应于第二列。我已经设置了以下 conf 文件(它们位于正确的目录中):
数据配置.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>
架构.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
有人知道我做错了什么吗?
在此先感谢您的帮助!!!
最佳答案
字段“id”出现在文档的其他地方。我对此进行了评论并且它起作用了。
关于java - 使用 solr 索引和搜索 MySQL,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3400558/