无法向 Solr 添加文档:Solr 响应错误(HTTP 400)(django + haystack + solr)

Jos*_*wen 5 python django solr pysolr django-haystack

我目前在生产中使用 Solr 4.2.0(大约在 2012 年建立)。我已经建立了一个新的开发环境,我升级了所有包(Django 1.8.10、PySolr 3.4.0、Haystack 2.4.1)并设置了 Solr 5.5.0

简而言之

我运行了 Solr,我的核心/集合是用 'basic_configs' 创建的,它似乎运行良好,除了在索引期间我遇到了很多类似于以下的错误:

All documents removed.
Indexing 9604 contracts
Failed to add documents to Solr: Solr responded with an error (HTTP 400): [Reason: ERROR: [d
oc=accounting.contract.22] unknown field 'status']
Failed to add documents to Solr: Solr responded with an error (HTTP 400): [Reason: ERROR: [d
oc=accounting.contract.70556] unknown field 'date_signed']
Failed to add documents to Solr: Solr responded with an error (HTTP 400): [Reason: ERROR: [d
oc=accounting.contract.72059] unknown field 'date_signed']
Failed to add documents to Solr: Solr responded with an error (HTTP 400): [Reason: ERROR: [d
oc=accounting.contract.73458] unknown field 'date_signed']
Run Code Online (Sandbox Code Playgroud)

查看 id,似乎大多数文档都很好,但足够频繁(列表还在继续)这些错误出现在所有表/索引中。

最终我遵循了这个有前途的 github 项目指南,但不幸的是它并没有为我解决问题。

我所做的,一步一步


  1. 使用本指南成功安装了 Solr 5.5.0(Web 界面在localhost:8983 上工作)
  2. 使用以下命令创建了一个名为“spng”的集合:sudo su - solr -c '/opt/solr/bin/solr create -c spng -d basic_configs'
  3. 前面提到的 github 项目指南中的 solr.xml 覆盖了我的 solr.xml (/srv/spng/src/django-haystack/haystack/templates/search_configuration/solr.xml)
  4. 只是为了确定我给了 solr.xml 文件 777 权限。

我的 settings.py 有以下条目:

HAYSTACK_CONNECTIONS = {
    'default': {
        'ENGINE': 'haystack.backends.solr_backend.SolrEngine',
        'URL': 'http://localhost:8983/solr/spng',
        'DEFAULT_OPERATOR': 'AND',
        'INCLUDE_SPELLING': True,
    },
}
Run Code Online (Sandbox Code Playgroud)
  1. 我创建了一个schema.xml(python manage.py build_solr_schema)并将它放在/var/solr/data/spng/conf/schema.xml
  2. 同样,为了确保我也给了 schema.xml 文件 777 权限。
  3. 我使用 curl 命令重新加载核心: curl ' http://localhost:8983/solr/admin/cores?action=RELOAD&core=spng&wt=json&indent=true '

回应是:

{
  "responseHeader":{
    "status":0,
    "QTime":300}}
Run Code Online (Sandbox Code Playgroud)
  1. 我还重新启动了 uwsgi 和 solr 以确保
  2. 此时我尝试运行 python manage.py rebuild_index 命令

如前所述,我最终遇到了以下错误:

All documents removed.
Indexing 9604 contracts
Failed to add documents to Solr: Solr responded with an error (HTTP 400): [Reason: ERROR: [d
oc=accounting.contract.22] unknown field 'status']
Failed to add documents to Solr: Solr responded with an error (HTTP 400): [Reason: ERROR: [d
oc=accounting.contract.70556] unknown field 'date_signed']
Failed to add documents to Solr: Solr responded with an error (HTTP 400): [Reason: ERROR: [d
oc=accounting.contract.72059] unknown field 'date_signed']
Failed to add documents to Solr: Solr responded with an error (HTTP 400): [Reason: ERROR: [d
oc=accounting.contract.73458] unknown field 'date_signed']
Run Code Online (Sandbox Code Playgroud)

有谁知道可能有什么问题?索引在我的生产服务器上运行没有错误,运行 4.2.0。我错过了设置还是 Solr 5.5.0 导致了这些错误?

Jos*_*wen 4

特别感谢elyograg在 Solr 的 IRC 频道(#solr on freenode)上为我提供帮助。

elyograg:如果您使用 basic_configs 中的库存 solrconfig.xml,那么您的架构位于名为“托管架构”的文件中——从 5.5 开始,所有示例配置默认都使用托管架构。

elyograg:将其(schema.xml 内容)放入托管架构中。您可能会更改 solrconfig.xml,但如果您保留默认值,那么对于试图帮助您的人来说,生活会更容易。

换句话说,从版本 5.5 开始,当使用 basic_configs 创建集合时,模式文件被称为“托管模式”,而不是 schema.xml(在我的例子中位于 /var/solr/data//conf/托管模式)

更新文件并重新加载核心后,索引完成且没有错误。

在未来的版本中要小心,因为elyograg还指出:

elyograg:添加 .xml 扩展名也可能是个好主意。我认为缺乏扩展不会对手工编辑产生太大的阻碍。

所以将来它可能会被称为 Managed-schema.xml