Data-config.xml 和 mysql - 我只能加载 "id" 列

Data-config.xml and mysql - I can load only "id" column

我在 Windows Server 2012 上安装了 Solr 5.0.0。我想将我的 table 中的所有数据加载到 solr 引擎中。

我的数据-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}]
  }}

我也想看看姓氏列。为什么我不能?

日志中的警告实际上是真正的问题。

如果您查看 solrconfig.xml 文件,您将有一个部分:

<schemaFactory class="ManagedIndexSchemaFactory">
  <bool name="mutable">true</bool>
  <str name="managedSchemaResourceName">managed-schema</str>
</schemaFactory>

这意味着您的 schema.xml 文件被忽略了。相反,将使用同一文件夹中的文件 managed-schema。

有几种方法可以解决这个问题。您可以注释掉托管架构部分并将其替换为

<schemaFactory class="ClassicIndexSchemaFactory"/>

或者另一种方法是删除托管架构文件。然后 SOLR 将在重新启动时读取 schema.xml 文件并生成一个新的托管模式。如果可行,那么您应该会在文件底部看到您的字段。

更多信息请看:

https://cwiki.apache.org/confluence/display/solr/Managed+Schema+Definition+in+SolrConfig