Search code examples
c#elasticsearchnest

ElasticSearch Doesn't Return Data Through Nest Call with Dynamic class


Am new to Elastic search and NEST, I am trying to get connected with my ES server through NEST. My ES Connection initialization looks like below.

ElasticClient client = null;
        public  void Connect()

        {

            var local = new Uri("http://192.168.40.95:9200/");

            var settings = new ConnectionSettings(local).DisableDirectStreaming();

            client = new ElasticClient(settings);

            settings.DefaultIndex("gisgcc18q4");

            ReadAllData();
        }

        public void ReadAllData()
        {
           var x= client.Search<dynamic>(s=> s.MatchAll());
        } 

The response is attached as image below, Image

I am Never getting any Hits, or data. Did i made any mistake in my connector, Also please suggest me good tutorials to convert JSOn ES query to NEST as well.


Solution

  • Looking at the Uri in the screenshot

    POST /gisgcc18q4/object/_search?typed_keys=true
    

    suggests that you're using a version older than 7, such as 5 or 6, where document types are used. In this case, the document type name "object" has been inferred from the dynamic type passed as the generic parameter argument, but I suspect that documents have not been indexed with a document type name of "object", but something else.

    If the index "gisgcc18q4" only contains one type of document, you can use

    var x = client.Search<dynamic>(s=> s.MatchAll().AllTypes());
    

    Or you can pass the specific document type name to use

    var x = client.Search<dynamic>(s=> s.MatchAll().Type("_doc"));
    

    A good getting started tutorial for the client is the elasticsearch-net-example GitHub repository. It is a walkthrough in building out a ASP.NET Core web application to search Nuget packages.