簡體   English   中英

如果使用Solr.NET將.NET Core與Solr連接,如何解決“遠程服務器返回錯誤:(404)未找到”的問題

[英]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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM