Solr return 400 用于带正斜杠的字符串字段

Solr return 400 for string field with forward slash

我正在尝试将一个 JSON 文档索引到 Solr 中,但是对于其中一个在字段中带有正斜杠的文档,Solr 失败并且 returns 400。

相关文档:

[
    {"key": "100", "path": "0"},
    **{"key": "200", "path": "0/6000"}**
]

错误:

SimplePostTool: WARNING: Solr returned an error #400 (Bad Request) for url: http://localhost:8983/solr/ss/update
SimplePostTool: WARNING: Response: {"responseHeader":{"status":400,"QTime":79},"error":{"msg":"ERROR: [doc=f92efb19-2786-49fd-a8ee-6d1e12fb0cb7] Error adding field 'path'='0/6000' msg=For input string: \"0/6000\"","code":400}}
SimplePostTool: WARNING: IOException while reading response: java.io.IOException: Server returned HTTP response code: 400 for URL: http://localhost:8983/solr/ss/update
1 files indexed.

我也尝试转义该字符串中的“/”,但没有成功

删除正斜杠效果很好。很奇怪

问题出在 Solr 5。从版本 5 开始,solr 默认管理模式并且不从 schema.xml 读取模式。当索引开始并且我的文档中的 "path" 字段是一个 int 时,solr 将其分析为 int,但是当涉及到 "path"="0/6000" 的文档时,它会抛出 NumberFormatException 并失败。

为此,您必须在 solrConfig.xml 中进行一些更改以使用 schema.xml 或坚持使用 solr 管理您的架构,Solr 5 提供了一个 API 来更新 Solr 生成的架构使用 Schema API(我最终使用了它)。