solrnet服务器连接错误.远程服务器返回错误:(400)错误请求

本文关键字:错误 服务器 请求 连接 solrnet 返回 | 更新日期: 2023-09-27 18:21:58

使用solrNet.dll和Microsoft.Practices.ServiceLocation.dll在带有solrNet的Tomcate windows xp上运行,我遇到错误远程服务器返回错误。(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();
    }

solrnet服务器连接错误.远程服务器返回错误:(400)错误请求

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

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