我正在尝试使用ASP.NET中的NEST获取ElasticSearch数据。使用按钮,单击该按钮后,我的数据将显示在文本框中。我是否需要将数据库放入项目中? ,当我单击该按钮时,不会显示任何数据。
我正在使用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>";
}
}
}}
您的应用程序正在运行哪个版本的.Net运行时?您使用的弹性搜索Nest API版本期望使用.Net标准版本2.0,但找不到。]