Elastic search Nest (.Net) Total and Documents don't match

I'm having the following situation: the Total from the Valid Nest Response is equals 2 and the Documents count equal 0. I'm not sure how that is possible.
In the code, I track down the total hits:

result = base._elasticContext.Client.Search<T>(s => s
            .From(pagination.Skip)
            .Size(pagination.Limit)
            .TrackTotalHits(true)
            .Query(q => q
            .Raw(resp)));

Found the solution. The problem was in my model. You see, my model was something like that:

public class Customer
    {        
        public string Id { get; set; }        

        public string Name { get; set; }
        
        public string Nickname { get; set; }
        
        public string PersonType { get; set; }
        
        public string Gender { get; set; }
        
        public string MaritalStatus { get; set; }
        
        [DataType(DataType.Date)]
        [DisplayFormat(DataFormatString = "{dd/MM/yyyy HH:mm:ss}")]
        public DateTime? BirthDate { get; set; }
    }

And this Index had Documents missing some fields, like:

public class Customer
    {        
        public string Id { get; set; }        

        public string Name { get; set; }
        
        public string PersonType { get; set; }
        
        public string Gender { get; set; }        
    }

The solution was adding the decorator PropertyName from Nest, to Map my model, like this:

public class Customer
    {
        [PropertyName("id")]
        public string Id { get; set; }

        [PropertyName("name")]
        public string Name { get; set; }

        [PropertyName("nickname")]
        public string Nickname { get; set; }

        [PropertyName("personType")]
        public string PersonType { get; set; }

        [PropertyName("gender")]
        public string Gender { get; set; }

        [PropertyName("maritalStatus")]
        public string MaritalStatus { get; set; }

        [PropertyName("birthDate")]
        [DataType(DataType.Date)]
        [DisplayFormat(DataFormatString = "{dd/MM/yyyy HH:mm:ss}")]
        public DateTime? BirthDate { get; set; }
    }

Now it works!

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.