0

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[] )
marc_s
  • 732,580
  • 175
  • 1,330
  • 1,459
Lazard
  • 11
  • 3
  • Does this answer your question? [What is a NullReferenceException and how do I fix it](https://stackoverflow.com/questions/4660142/what-is-a-nullreferenceexception-and-how-do-i-fix-it)? – Qing Guo Nov 07 '22 at 02:20

0 Answers0