[英]How to fix “The remote server returned an error: (404) Not Found” if connecting .NET Core with Solr using Solr.NET
我想使用Solr.NET从运行的.NET Core应用程序与本地运行的solr实例建立连接。 问题是尝试查询solr时总是出现404错误。
这是代码:
在Startup.cs中,我通过以下方式将实例添加到IServiceCollection:
services.AddSolrNet("https://localhost:8982/solr");
在我的控制器中,我尝试了这个:
List<AppointmentSearchResult> content = new List<AppointmentSearchResult>();
SolrQueryResults<AppointmentSearchResult> results = _solr.Query(new SolrQueryByField("locked", "true"));
foreach (AppointmentSearchResult result in results)
{
content.Add(result);
}
string json = JsonConvert.SerializeObject(content);
return this.Content(json);
AppointmentSearchResult类如下所示:
public class AppointmentSearchResult
{
[SolrUniqueKey("id")]
public string id { get; set; }
[SolrField("locked")]
public bool? locked { get; set; }
[SolrField("unique_key")]
public string unique_key { get; set; }
[SolrField("busy")]
public bool? busy { get; set; }
[SolrField("done")]
public bool? done { get; set; }
[SolrField("duration")]
public string duration { get; set; }
[SolrField("customerid")]
public double customerid { get; set; }
[SolrField("planning")]
public string planning { get; set; }
[SolrField("employee_id")]
public int? employee_id { get; set; }
[SolrField("date")]
public DateTime date { get; set; }
[SolrField("done_date")]
public DateTime? done_date { get; set; }
[SolrField("calendar_event_id")]
public string calendar_event_id { get; set; }
[SolrField("note")]
public string note { get; set; }
}
这是正确的方法吗? 我总是收到错误:处理请求时发生未处理的异常。 WebException:远程服务器返回错误:(404)找不到。
如果有人对我有建议,那就太好了!
最好的问候,安德里亚斯
Solr连接是否需要用户名和密码? 尝试这个。
services.AddSolrNet(o =>
{
o.ServerUrl = "https://localhost:8982/solr";
o.UserName = "sa";
o.Password = "sa";
});
SolrNet v1.0.17的文档显示了两个IServiceCollection附加项,一个与常规solr实例相同,另一个用于指定了文档类型的特定核心。 例如
services.AddSolrNet("https://localhost:8982/solr");
services.AddSolrNet<AppointmentSearchResult>("https://localhost:8982/solr/core1");
https://github.com/SolrNet/SolrNet/blob/master/Documentation/Initialization.md
这是我在Startup.cs中完成的操作,没有遇到您遇到的问题。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.