I get this error:
An unhandled exception occurred while processing the request.
NullReferenceException: Object reference not set to an instance of an object.
WebApplication1.Controllers.HomeController.Index(string query) in HomeController.cs, line 26
Connection
public void ConfigureServices(IServiceCollection services)
{
var pool = new SingleNodeConnectionPool(new Uri("http://localhost:9200"));
var settings = new ConnectionSettings(pool).DefaultIndex("company");
settings.DefaultFieldNameInferrer(p => p);
var client = new ElasticClient(settings);
services.AddSingleton(client);
services.AddControllersWithViews();
}
Model
public class Company
{
public string ComName { get; set; }
public string ComAdd { get; set; }
}
public IActionResult Index(string query)
{
ISearchResponse<Company> results;
query = query.ToLower();
results = _ecclient.Search<Company>( s => s
.Query( q => q
.MatchAll()
)
);
return View(results);
}
Elasticsearch
{
"_index": "company",
"_type": "_doc",
"_id": "OeKcQ4QBGtl5ZPboiD-f",
"_score": 1.0,
"_source": {
"ComName": "lazard",
"ComAdd": "USA"
}
},
WebApplication1.Controllers.HomeController.Index(string query)
in HomeController.cs
:
query = query.ToLower();
lambda_method(Closure , object , object[] )