【问题标题】:solrnet server connection error. The remote server returned an error: (400) Bad Requestsolrnet 服务器连接错误。远程服务器返回错误:(400) Bad Request
【发布时间】:2013-07-09 05:59:05
【问题描述】:

使用 solrnet.dll 和 Microsoft.Practices.ServiceLocation.dll 在 Tomcat windows xp 上运行 solrNet,我收到错误远程服务器返回错误。(400) 错误请求。

在此代码上添加内容时

solr.Add(new Article()
    {
        _id = 1,
        _title = "My Laptop",
        _content = "My laptop is portable power station",
        _tags = new List<string>() {
        "laptop","computer","device"
        }

    });

我正在使用下面的代码...

using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using SolrNet;
using SolrNet.Attributes;
using SolrNet.Commands.Parameters;
using Microsoft.Practices.ServiceLocation;

namespace solrIndex_creator
{

 class Article
  {
    [SolrUniqueKey("id1")]
    public int _id { get; set; }

    [SolrField("title1")]
    public string _title { get; set; }

    [SolrField("content1")]
    public string _content { get; set; }

    [SolrField("tag1")]
    public List<string> _tags { get; set; }

    ISolrOperations<Article> solr;

   public void _write_Data()
    {
      Startup.Init<Article>("http://localhost:8080/solr/");
      solr = ServiceLocator.Current.GetInstance<ISolrOperations<Article>>();

       solr.Add(new Article()
        {
            _id = 1,
            _title = "My Laptop",
            _content = "My laptop is portable power station",
            _tags = new List<string>() {
            "laptop","computer","device"
            }

        });

       solr.Add(new Article()
        {
            _id = 2,
            _title = "my iphone",
            _content = "my iphone consumes power",
            _tags = new List<string>() {   
                "phone",   
                "apple",  
                "device"  
            }
        });

        solr.Add(new Article()
        {
            _id = 3,
            _title = "your blackberry",
            _content = "your blackberry has an alt key",
            _tags = new List<string>() {   
            "phone",   
            "rim",  
            "device"  
            }
        });
        solr.Commit();
    }

【问题讨论】:

    标签: c# solr indexing lucene.net solrnet


    【解决方案1】:

    此错误可能与您的 Solr schema.xml &lt;fields&gt; 设置和您的 Article 类不匹配有关。您应该能够调试您的程序并检查 Bad Request 错误以获取有关问题所在的更多详细信息。或者您也可以检查 Solr 的服务器日志(在您的托管容器中,例如 Jetty、Tomcat)以了解更多详细信息。

    此外,我会将 Article 类上的 Tags 属性更改为更通用的 ICollection,就像 SolrNet Mapping wiki 上的多值示例一样。

    【讨论】:

    • thnks 我已经解决了这个错误,但是当我提交像 solr.Commit() 这样的索引时出现错误 'org.apache.solr.common.SolrException: Unknown commit parameter 'waitFlush''跨度>
    • 这是早期版本的 SolrNet 库和 Solr 4.X 版本的问题。您可以从构建服务器下载更高版本的 SolrNet - teamcity.codebetter.com/…(注意:单击 Artifacts 链接以获取可下载的 zip 文件)。
    • +1 for 从构建服务器下载,我花了将近一个小时找出Commit上的异常。