SolrNet:SolrConnectionException(400)在尝试添加和提交时出现错误请求
本文关键字:提交 请求 错误 添加 SolrConnectionException SolrNet | 更新日期: 2023-09-27 18:22:44
我已经到了SolrNet执行"Add"方法的地步,但当我尝试"Commit"时,我收到错误。以下是我的schema.xml、模型、调用它的代码以及我得到的错误。更奇怪的是,尽管出现了错误,但在我重新启动Tomcat后,该模型会被添加到我的Solr索引中(因此,尽管出现错误,它仍然会添加我的模型,但不会立即添加):
schema.xml(字段和字段类型):
<!-- Fields -->
<field name="part_numbers" type="my_string_exact" indexed="true" stored="true" multiValued="true" />
<field name="page_url" type="my_string_exact" indexed="true" stored="true" />
<field name="product_name" type="my_string" indexed="true" stored="true" />
<!-- FieldTypes -->
<fieldType name="my_string_exact" class="solr.StrField" sortMissingLast="true" omitNorms="true"/>
<fieldType name="my_string" class="solr.TextField" sortMissingLast="true" omitNorms="true">
<analyzer type="index">
<tokenizer class="solr.KeywordTokenizerFactory" />
<filter class="solr.LowerCaseFilterFactory" />
</analyzer>
<analyzer type="query">
<tokenizer class="solr.KeywordTokenizerFactory" />
<filter class="solr.LowerCaseFilterFactory" />
</analyzer>
</fieldType>
<fieldType name="my_int" class="solr.IntField" omitNorms="true" />
型号(Product.cs)*注意-PageId使用Solr默认的"id",这是一个字符串,唯一且必需:
public class Product
{
[SolrUniqueKey("id")]
public string PageId { get; set; }
[SolrField("part_numbers")]
public ICollection<string> PartNumbers { get; set; }
[SolrField("page_url")]
public string PageUrl { get; set; }
[SolrField("product_name")]
public string Name { get; set; }
}
代码初始化,调用Add and Commit*注意-这是一个单元测试,所以init只调用一次:
Startup.Init<Product>("http://localhost:8080/solr");
Product testProd = new Product() {
EPiPageId = "44",
Name = "TestProd3",
PageUrl = "/TestProd3",
PartNumbers = new List<string>() { "000022222", "000000333333" }
};
var solr = ServiceLocator.Current.GetInstance<ISolrOperations<Product>>();
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:
EDIT感谢Paige的回答:问题是"waitFlush"错误,这是旧版本SolrNet的错误。我使用的SolrNet版本来自VS NuGet,为0.3.1(我认为这是他们最新的稳定版本)。他们的谷歌代码网站没有他们的最新版本,但有构建服务器(这里:http://teamcity.codebetter.com/project.html?projectId=project36&"artifacts"下的guest=1)确实有最新的修复程序。为我解决了问题。
我猜您可能在Tomcat日志中看到waitFlush
错误,并且您使用的是Solr的4.X版本。如果是这样的话,这就是Solr4.x和旧版本SolrNet的已知问题。若要解决此问题,请升级到SolrNet库的更高版本。您可以从生成服务器下载它。单击Artifacts以获取到zip的链接。