【问题标题】:elastic search in .net with NEST使用 NEST 在 .net 中进行弹性搜索
【发布时间】:2020-09-30 22:56:43
【问题描述】:

我正在尝试在 ASP.NET 中使用 NEST 获取 ElasticSearch 数据。使用一个按钮,当它单击时,我的数据将显示在 TextBox 中。 我需要将我的数据库放在项目中吗? ,当我点击按钮时没有数据显示。

我正在使用 Visual Studio 2015,.NET Framework 4.6.1

我是初学者,所以我无法处理发生的这个错误。 我会提供我的代码。

错误:

NuGet 包:

namespace ElasticsearchWeb{
public class shekspir
{
    public string type { get; set; }
    public int line_id { get; set; }
    public string play_name { get; set; }
    public int speech_number { get; set; }
    public float line_number { get; set; }
    public string speaker { get; set; }
    public string text_entry { get; set; }
}
public partial class Default : System.Web.UI.Page
{
    public static Uri GetElasticHost()
    {
        var host = "http://localhost:9200";
        return new Uri(host);
    }
    public static ElasticClient GetElasticClient(ConnectionSettings settings = null)
    {
        if (settings == null)
        {
            var node = GetElasticHost();
            var pool = new SingleNodeConnectionPool(node);
            settings = new ConnectionSettings(pool);
        }
        settings.DisableDirectStreaming(true);
        var client = new ElasticClient(settings);
        return client;
    }

    public static List<shekspir> GetAllShekspir(int ID)
    {
        var client = GetElasticClient();

        ISearchResponse<shekspir> result = null;

        result = client.Search<shekspir>(x => x
        .Index("shekspir")
        .Query(q => q
            .MatchAll())

        );

        List<shekspir> list = new List<shekspir>();
        foreach (var r in result.Hits)
        {
            shekspir a = r.Source;
            list.Add(a);
        }

        return list;
    }
    protected void Page_Load(object sender, EventArgs e)
    {

    }

    protected void Button1_Click(object sender, EventArgs e)
    {

        List<shekspir> list = GetAllShekspir(1);

        foreach (shekspir u in list)
        {
            litInfo.Text += u.play_name + ": " + u.text_entry + "<br>";


        }

    }
}}

【问题讨论】:

    标签: asp.net .net visual-studio elasticsearch nest


    【解决方案1】:

    您的应用程序正在运行哪个版本的 .Net 运行时?您使用的弹性搜索 Nest API 版本需要 .Net 标准版本 2.0,但它无法找到。

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2019-10-22
      • 2021-05-18
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多