【发布时间】:2015-04-07 13:12:40
【问题描述】:
我在 Windows Server 2012 上安装了 Solr 5.0.0。我想将表中的所有数据加载到 solr 引擎中。
我的 data-config.xml 如下所示:
<?xml version="1.0" encoding="UTF-8" ?>
<!--# define data source -->
<dataConfig>
<dataSource type="JdbcDataSource"
driver="com.mysql.jdbc.Driver"
url="jdbc:mysql://localhost:3306/database"
user="root"
password="root"/>
<document>
<entity name="my_table"
pk="id"
query="SELECT ID, LASTNAME FROM my_table limit 2">
<field column="ID" name="id" type="string" indexed="true" stored="true" required="true" />
<field column="LASTNAME" name="lastname" type="string" indexed="true" stored="true"/>
</entity>
</document>
</dataConfig>
当我选择数据导入时,我得到了答案:
Indexing completed. Added/Updated: 2 documents. Deleted 0 documents
Requests: 1, Fetched: 2, Skipped: 0, Processed: 2
和原始调试响应:
{
"responseHeader": {
"status": 0,
"QTime": 280
},
"initArgs": [
"defaults",
[
"config",
"data-config.xml"
]
],
"command": "full-import",
"mode": "debug",
"documents": [
{
"id": [
1983
],
"_version_": [
1497798459776827400
]
},
{
"id": [
1984
],
"_version_": [
1497798459776827400
]
}
],
"verbose-output": [
"entity:my_table",
[
"document#1",
[
"query",
"SELECT ID,LASTNAME FROM my_table limit 2",
"time-taken",
"0:0:0.8",
null,
"----------- row #1-------------",
"LASTNAME",
"Gates",
"ID",
1983,
null,
"---------------------------------------------"
],
"document#2",
[
null,
"----------- row #1-------------",
"LASTNAME",
"Doe",
"ID",
1984,
null,
"---------------------------------------------"
],
"document#3",
[]
]
],
"status": "idle",
"importResponse": "",
"statusMessages": {
"Total Requests made to DataSource": "1",
"Total Rows Fetched": "2",
"Total Documents Skipped": "0",
"Full Dump Started": "2015-04-07 15:05:22",
"": "Indexing completed. Added/Updated: 2 documents. Deleted 0 documents.",
"Committed": "2015-04-07 15:05:22",
"Optimized": "2015-04-07 15:05:22",
"Total Documents Processed": "2",
"Time taken": "0:0:0.270"
}
}
最后当我查询 Solr 时
http://localhost:8983/solr/test/query?q=*:*
我有一个答案:
{
"responseHeader":{
"status":0,
"QTime":0,
"params":{
"q":"*:*"}},
"response":{"numFound":2,"start":0,"docs":[
{
"id":"1983",
"_version_":1497798459776827392},
{
"id":"1984",
"_version_":1497798459776827393}]
}}
我也想查看姓氏列。为什么我不能?
【问题讨论】:
-
发布您的 schema.xml
-
看起来您正在尝试直接在
schema.xml中直接在data-config.xml中定义您的字段,但我认为这不是实际上可能。data-config.xml中的<field>元素更多地是关于将返回的 SQLcolumn与预期的 Solr 字段name映射。您是否在schema.xml中定义lastname字段?如果查询返回的字段未映射到定义的字段,数据导入器通常会静默删除这些字段。 -
感谢您的回答!所以:1.我将 data-config.xml 更改为:
<entity name="jn_person" pk="id" query="SELECT ID, lastname FROM jn_person limit 2"> <field column="ID" name="id" /> <field column="lastname" name="lastname"/> </entity>2.并添加行<!-- New field --> <field name="lastname" type="string" indexed="true" stored="true" multiValued="true" />我的 schema.xml 如下所示:pastebin.com/xLgsv31h -
我在日志中有一个警告:
ManagedIndexSchemaFactory The schema has been upgraded to managed, but the non-managed schema schema.xml is still loadable. PLEASE REMOVE THIS FILE.在我看来,我的问题和这个温暖没有关系,但我不确定
标签: solr lucene dataimporthandler