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

**URL:** <https://discuss.elastic.co/t/elastic-search-nest-net-total-and-documents-dont-match/296218>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [February 3, 2022, 5:55pm UTC](https://discuss.elastic.co/t/elastic-search-nest-net-total-and-documents-dont-match/296218 "2022-02-03T17:55:59Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![kqgcm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kqgcm/32/101333_2.png) [@kqgcm](https://discuss.elastic.co/u/kqgcm)\
**Post date:** [February 3, 2022, 5:55pm UTC](https://discuss.elastic.co/t/elastic-search-nest-net-total-and-documents-dont-match/296218/1 "2022-02-03T17:55:59Z")

</div>

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:

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

```

 ![bug](https://us1.discourse-cdn.com/elastic/original/3X/2/f/2fb33f1de3c4503f0602edc15ec02ba89edbac8b.png)

---

<div class="post-metadata">

**Author:** ![kqgcm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/kqgcm/32/101333_2.png) [@kqgcm](https://discuss.elastic.co/u/kqgcm)\
**Post date:** [February 3, 2022, 7:59pm UTC](https://discuss.elastic.co/t/elastic-search-nest-net-total-and-documents-dont-match/296218/2 "2022-02-03T19:59:41Z")

</div>

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

```auto
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:

```auto
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:

```auto
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!

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [March 3, 2022, 8:00pm UTC](https://discuss.elastic.co/t/elastic-search-nest-net-total-and-documents-dont-match/296218/3 "2022-03-03T20:00:27Z")

</div>

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