【发布时间】:2020-09-30 22:56:43
【问题描述】:
我正在尝试在 ASP.NET 中使用 NEST 获取 ElasticSearch 数据。使用一个按钮,当它单击时,我的数据将显示在 TextBox 中。 我需要将我的数据库放在项目中吗? ,当我点击按钮时没有数据显示。
我正在使用 Visual Studio 2015,.NET Framework 4.6.1
我是初学者,所以我无法处理发生的这个错误。 我会提供我的代码。
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