在 Solr 5 中使用 schema.xml 而不是托管模式。1.X

Using schema.xml instead of managed schema with Solr 5.1.X

我正在尝试将 schema.xml 与最新版本的 Solr (5.1.0) 一起使用。似乎默认情况下 Solr 5.1.0 使用托管架构,但我想对特定集合使用 schema.xml。

所以我创建了一个新集合(在 windows 上使用 solr create -c my_collection 并从

复制 schema.xml
server\solr\configsets\basic_configs\conf\schema.xml

server\solr\my_collection\conf\schema.xml

之后我在

中更改设置
server\solr\my_collection\conf\solrconfig.xml 

使用

<schemaFactory class="ClassicIndexSchemaFactory"/>

执行此操作后,我在启动服务器时遇到异常:

org.apache.solr.common.SolrException:org.apache.solr.common.SolrException:    fieldType 'booleans' not found in the schema

我是不是做错了什么?这种逻辑不应该行得通吗?

更新: Stractrace 看起来像这样:

org.apache.solr.common.SolrException: fieldType 'booleans' not found in the schema
at org.apache.solr.core.SolrCore.<init>(SolrCore.java:885)
at org.apache.solr.core.SolrCore.<init>(SolrCore.java:652)
at org.apache.solr.core.CoreContainer.create(CoreContainer.java:518)
at org.apache.solr.core.CoreContainer.call(CoreContainer.java:283)
at org.apache.solr.core.CoreContainer.call(CoreContainer.java:277)
at java.util.concurrent.FutureTask.run(FutureTask.java:266)
at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
at java.lang.Thread.run(Thread.java:745)
Caused by: org.apache.solr.common.SolrException: fieldType 'booleans' not found in the schema
at org.apache.solr.update.processor.AddSchemaFieldsUpdateProcessorFactory$TypeMapping.populateValueClasses(AddSchemaFieldsUpdateProcessorFactory.java:244)
at org.apache.solr.update.processor.AddSchemaFieldsUpdateProcessorFactory.inform(AddSchemaFieldsUpdateProcessorFactory.java:170)
at org.apache.solr.core.SolrResourceLoader.inform(SolrResourceLoader.java:620)
at org.apache.solr.core.SolrCore.<init>(SolrCore.java:868)

问题是您引用的字段类型 booleans 未在您的 schema.xml 文件中定义。创建核心时,会在 server\solr\my_collection\conf\ 中创建一个文件 managed-schema。将此文件重命名为 schema.xml 并使用 ClassicIndexSchemaFactory 重新启动 solr,它将正常工作。

我在这里遇到的问题与实际使用 booleans 字段类型无关。问题是新升级的 solrconfig.xml 文件有一个默认启用的未知字段处理器,它需要 booleans 字段类型,可能还有一些其他字段类型。

这些都是在新示例 schema.xml 中默认定义的,但很可能在您的旧示例 schema.xml 中没有定义。

我的解决方案是注释掉 solrconfig.xml 中的 <updateRequestProcessorChain name="add-unknown-fields-to-the-schema"> 部分。

或者,您可以只替换 solrconfig.xml.

字段类型 {booleans} 未在 schema.xml 中定义。

修复步骤,

  • 删除集合
  • managed-schema 文件重命名为 schema.xml
  • 修改solrconfig.xml以替换schemaFactoryclass。
  • a) 删除任何 ManagedIndexSchemaFactory 定义(如果存在)。
  • b) 添加一个ClassicIndexSchemaFactory定义如下图,

<schemaFactory class="ClassicIndexSchemaFactory"/>

  • solrconfig.xml 中将 autoCreateFields 更新为 false 否则您将得到

This IndexSchema is not mutable 错误。

${update.autoCreateFields:false}

  • 重新创建集合。