# ElasticSearch NEST - all fields are NULL

**URL:** <https://discuss.elastic.co/t/elasticsearch-nest-all-fields-are-null/221754>\
**Category:** Elasticsearch\
**Created:** [March 2, 2020, 6:27pm UTC](https://discuss.elastic.co/t/elasticsearch-nest-all-fields-are-null/221754 "2020-03-02T18:27:12Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Julius\_Kukonenko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/julius_kukonenko/32/63653_2.png) [@Julius\_Kukonenko](https://discuss.elastic.co/u/Julius_Kukonenko)\
**Post date:** [March 2, 2020, 6:27pm UTC](https://discuss.elastic.co/t/elasticsearch-nest-all-fields-are-null/221754/1 "2020-03-02T18:27:13Z")

</div>

I'm trying to retrieve data from elastic search with NEST. Everything would be good, but NEST all fields return null. However, in debug mode I see that it counts the documents correctly but not showing the value of fields.

 ![](https://us1.discourse-cdn.com/elastic/original/3X/b/1/b13197cb35c2cfd7001f37aa896c34f3d9c8284a.png)  
 ![](https://us1.discourse-cdn.com/elastic/original/3X/1/8/186bd4f37f7b0050602d5758f2db6599249d8857.png)  
What I already did:

- checked mapping and its seems fine to me.
- tried String Querry.
- tried to get source and then read data.
- tried [NEST returns null instead of fields](https://stackoverflow.com/questions/50684934/nest-returns-null-instead-of-fields) those solution did not help either.
- Renamed Product.cs field names to camelCase did not help either.  
Heres my code right now:

```auto
public class ElasticSearch
{
    private ElasticClient _client;

    public ElasticSearch()
    {
        var node = new Uri("http://localhost:9200");
        var settings = new ConnectionSettings(node);
        settings.DefaultIndex("logsystem.logs");
        _client = new ElasticClient(settings);
    }

    public void searchResults()
    {
        var searchResults = _client.Search<Product>(s => s.AllIndices());

    }
}

```

Product.cs

```auto
    [BsonIgnoreExtraElements]
    public class Product
    {
        [BsonId]
        [BsonIgnore]
        public ObjectId Id { get; set; }
        [Required]
        public string Name { get; set; }
        [Required]
        public string ProductLicenseKey { get; set; }
        [Required]
        public string Action { get; set; }
        [Required]
        public string ActionName { get; set; }
        [Required]
        public string MachineId { get; set; }
    }

```

Mapping in ElasticSearch:

```auto
{
"logsystem.logs": {
    "mappings": {
        "properties": {
            "Action": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "ActionName": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "MachineId": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "Name": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            },
            "ProductLicenseKey": {
                "type": "text",
                "fields": {
                    "keyword": {
                        "type": "keyword",
                        "ignore_above": 256
                    }
                }
            }
        }
    }
}
}

```

ElasticSearch Documents get via postman:

```auto
{
"took": 11,
"timed_out": false,
"_shards": {
    "total": 1,
    "successful": 1,
    "skipped": 0,
    "failed": 0
},
"hits": {
    "total": {
        "value": 6,
        "relation": "eq"
    },
    "max_score": 1.0,
    "hits": [
        {
            "_index": "logsystem.logs",
            "_type": "_doc",
            "_id": "5e5c1ca2aaa6f1245cc38895",
            "_score": 1.0,
            "_source": {
                "Action": "Button",
                "ActionName": "Fixed Single Generation",
                "MachineId": "987-654-321",
                "Name": "System",
                "ProductLicenseKey": "123-456-789"
            }
        },
        {
            "_index": "logsystem.logs",
            "_type": "_doc",
            "_id": "5e5c1cb0aaa6f1245cc38896",
            "_score": 1.0,
            "_source": {
                "Action": "Button",
                "ActionName": "Fixed Multiple Generation",
                "MachineId": "987-654-321",
                "Name": "System",
                "ProductLicenseKey": "123-456-789"
            }
        },
        {
            "_index": "logsystem.logs",
            "_type": "_doc",
            "_id": "5e5c1cbdaaa6f1245cc38897",
            "_score": 1.0,
            "_source": {
                "Action": "Button",
                "ActionName": "Trackers Single Generation",
                "MachineId": "987-654-321",
                "Name": "System",
                "ProductLicenseKey": "123-456-789"
            }
        },
        {
            "_index": "logsystem.logs",
            "_type": "_doc",
            "_id": "5e5c1ccbaaa6f1245cc38898",
            "_score": 1.0,
            "_source": {
                "Action": "Button",
                "ActionName": "Trackers Multiple Generation",
                "MachineId": "987-654-321",
                "Name": "System",
                "ProductLicenseKey": "123-456-789"
            }
        },
        {
            "_index": "logsystem.logs",
            "_type": "_doc",
            "_id": "5e5c1cd3aaa6f1245cc38899",
            "_score": 1.0,
            "_source": {
                "Action": "Button",
                "ActionName": "Fixed Multiple Generation",
                "MachineId": "987-654-321",
                "Name": "System",
                "ProductLicenseKey": "123-456-789"
            }
        },
        {
            "_index": "logsystem.logs",
            "_type": "_doc",
            "_id": "5e5c1ce0aaa6f1245cc3889a",
            "_score": 1.0,
            "_source": {
                "Action": "Button",
                "ActionName": "Tree Generation",
                "MachineId": "987-654-321",
                "Name": "System",
                "ProductLicenseKey": "123-456-789"
            }
        }
    ]
 }
}

```

Maybe my mapping is not right? any answer would help. Thanks.  
By the way, data to elasticSearch was inserted using monstache from mongo database.

---

<div class="post-metadata">

**Author:** ![forloop](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/forloop/32/9021_2.png) [@forloop](https://discuss.elastic.co/u/forloop)\
**Post date:** [March 3, 2020, 12:02am UTC](https://discuss.elastic.co/t/elasticsearch-nest-all-fields-are-null/221754/2 "2020-03-03T00:02:03Z")

</div>

I suspect the issue is that by default, the client expects to deserialize camel-cased JSON object keys to the POCO properties, and is strict about casing.

You can override this default using `DefaultFieldNameInferrer` on `ConnectionSettings`. Since the mapping contains Pascal cased field names that look like they map directly to the POCO property names, the following should work

```auto
var node = new Uri("http://localhost:9200");
var settings = new ConnectionSettings(node)
	.DefaultIndex("logsystem.logs")
	.DefaultFieldNameInferrer(p => p);

var client = new ElasticClient(settings);

```

---

<div class="post-metadata">

**Author:** ![Julius\_Kukonenko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/julius_kukonenko/32/63653_2.png) [@Julius\_Kukonenko](https://discuss.elastic.co/u/Julius_Kukonenko)\
**Post date:** [March 3, 2020, 7:43am UTC](https://discuss.elastic.co/t/elasticsearch-nest-all-fields-are-null/221754/3 "2020-03-03T07:43:37Z")

</div>

Thank you, that helped!

---

<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 31, 2020, 7:43am UTC](https://discuss.elastic.co/t/elasticsearch-nest-all-fields-are-null/221754/4 "2020-03-31T07:43:52Z")

</div>

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