我已经到了SolrNet执行“添加”方法的地步,但是当我尝试“提交”时就是收到错误.以下是我的schema.xml,模型,调用它的代码以及出现的错误.甚至更奇怪的是,尽管有错误,但是在重新启动Tomcat之后,该模型仍添加到了我的Solr索引中(因此尽管有错误,但仍然立即添加了我的模型):
schema.xml(字段和字段类型):
型号(Product.cs)*注意-PageId使用Solr默认“ id”,它是一个字符串,唯一且必填:
public class Product
{
[SolrUniqueKey("id")]
public string PageId { get; set; }
[SolrField("part_numbers")]
public ICollection PartNumbers { get; set; }
[SolrField("page_url")]
public string PageUrl { get; set; }
[SolrField("product_name")]
public string Name { get; set; }
}
代码初始化,调用添加并提交*注意-这是一个单元测试,因此init仅被调用一次:
Startup.Init("http://localhost:8080/solr");
Product testProd = new Product() {
EPiPageId = "44",
Name = "TestProd3",
PageUrl = "/TestProd3",
PartNumbers = new List() { "000022222", "000000333333" }
};
var solr = ServiceLocator.Current.GetInstance>();
solr.Add(testProd);
solr.Commit(); // Bad Request Error occurs here.
错误讯息:
SolrNet.Exceptions.SolrConnectionException was unhandled by user code
HResult=-2146232832
Message=The remote server returned an error: (400) Bad Request.
Source=SolrNet
StackTrace:
at SolrNet.Impl.SolrConnection.Post(String relativeUrl, String s) in c:\prg\SolrNet\svn\SolrNet\Impl\SolrConnection.cs:line 104
at SolrNet.Commands.CommitCommand.Execute(ISolrConnection connection) in c:\prg\SolrNet\svn\SolrNet\Commands\CommitCommand.cs:line 71
at SolrNet.Impl.SolrBasicServer`1.Send(ISolrCommand cmd) in c:\prg\SolrNet\svn\SolrNet\Impl\SolrBasicServer.cs:line 87
at SolrNet.Impl.SolrBasicServer`1.SendAndParseHeader(ISolrCommand cmd) in c:\prg\SolrNet\svn\SolrNet\Impl\SolrBasicServer.cs:line 91
at SolrNet.Impl.SolrBasicServer`1.Commit(CommitOptions options) in c:\prg\SolrNet\svn\SolrNet\Impl\SolrBasicServer.cs:line 54
at SolrNet.Impl.SolrServer`1.Commit() in c:\prg\SolrNet\svn\SolrNet\Impl\SolrServer.cs:line 24
InnerException: System.Net.WebException
HResult=-2146233079
Message=The remote server returned an error: (400) Bad Request.
Source=System
StackTrace:
at System.Net.HttpWebRequest.GetResponse()
at HttpWebAdapters.Adapters.HttpWebRequestAdapter.GetResponse() in c:\prg\SolrNet\svn\HttpWebAdapters\Impl\HttpWebRequestAdapter.cs:line 36
at SolrNet.Impl.SolrConnection.GetResponse(IHttpWebRequest request) in c:\prg\SolrNet\svn\SolrNet\Impl\SolrConnection.cs:line 160
at SolrNet.Impl.SolrConnection.Post(String relativeUrl, String s) in c:\prg\SolrNet\svn\SolrNet\Impl\SolrConnection.cs:line 101
InnerException:
编辑感谢Paige的回答:问题是“ waitFlush”错误,它是旧版本SolrNet的错误.我使用的SolrNet版本来自VS NuGet,版本为0.3.1(我认为这是他们的最新稳定版本).他们的google代码站点没有最新的构建,但是构建服务器(此处为“ artifacts”下的http://teamcity.codebetter.com/project.html?projectId=project36&guest=1)确实具有最新的错误修复程序.问题为我解决.