# ElasticSearch Nest query returning Null values for every field?

**URL:** <https://discuss.elastic.co/t/elasticsearch-nest-query-returning-null-values-for-every-field/284796>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [September 22, 2021, 4:16am UTC](https://discuss.elastic.co/t/elasticsearch-nest-query-returning-null-values-for-every-field/284796 "2021-09-22T04:16:46Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![bensalerno](https://avatars.discourse-cdn.com/v4/letter/b/9dc877/32.png) [@bensalerno](https://discuss.elastic.co/u/bensalerno)\
**Post date:** [September 22, 2021, 4:16am UTC](https://discuss.elastic.co/t/elasticsearch-nest-query-returning-null-values-for-every-field/284796/1 "2021-09-22T04:16:46Z")

</div>

I finally got my Nest client set up, however, the results of every field are populated as null instead of the expected values.

I looked at these [c# - ElasticSearch NEST - all fields are NULL - Stack Overflow](https://stackoverflow.com/questions/60490620/elasticsearch-nest-all-fields-are-null) and [c# - NEST returns null instead of fields - Stack Overflow](https://stackoverflow.com/questions/50684934/nest-returns-null-instead-of-fields) but neither was able to help me fix the issue. This is my code - super basic:

```auto
private static Nest.ConnectionSettings settings = new ConnectionSettings(new Uri("uri-link"))
            .BasicAuthentication("usr", "pw")
            .ClientCertificate(cert) // my pfx certificate
            .DisableDirectStreaming()
            .DefaultIndex("index");

var searchResponse = Event.client.Search<mdl.Event>(s => s
                    .From(0)
                    .Size(1000)
                    .Query(q => q
                        .MatchAll())));

```

When I add

```auto
.DefaultFieldNameInferrer(p => p);

```

to my connection settings, I get a new error:

An exception of type 'Elasticsearch.Net.UnexpectedElasticsearchClientException' occurred in Elasticsearch.Net.dll but was not handled in user code: 'expected:'String Begin Token', actual:'1631555771000', at offset:344'. I'm not sure what this error means or why it is happening?

All of the fields in the documents do begin with a Capital letter if that means anything.

As you can see I'm just trying to list every item in the cluster. I cannot figure out why this is returning all fields null though. Is there a problem with my connection or something? Any help is appreciated?

---

<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:** [October 17, 2021, 11:28pm UTC](https://discuss.elastic.co/t/elasticsearch-nest-query-returning-null-values-for-every-field/284796/2 "2021-10-17T23:28:31Z")

</div>

The following exception

> [@bensalerno](#):
>
> An exception of type 'Elasticsearch.Net.UnexpectedElasticsearchClientException' occurred in Elasticsearch.Net.dll but was not handled in user code: 'expected:'String Begin Token', actual:'1631555771000', at offset:344'.

indicates that the client is expecting to deserialize a string field, but was passed a numeric value. A culprit that comes to mind here is a `date` property in Elasticsearch mapped as Unix epoch offset e.g. `epoch_millis`, that maps to a `DateTime` or `DateTimeOffset` property on the document.

The serializer used by NEST expects to deserialize a string in ISO8601 format to `DateTime` and `DateTimeOffset` by default. If the field uses `epoch_millis` format however, you should be able to attribute the type property with `MachineLearningDateTimeAttribute` to deserialize from a number representing milliseconds since epoch

```auto
public class MyDocument
{
    [MachineLearningDateTime]
    public DateTimeOffset MyDateTime { get; set; }
}

```

The `MachineLearningDateTimeAttribute` is used internally for some of the Machine Learning APIs, but since it's public, it can help out here.

An alternative approach would be to index this field with IS08601 format i.e. `yyyy-MM-dd'T'hh:mm:ss.fffffff` if you can, which the client will be able to deserialize.

Another alternative is to map the field to a `long` property for deserialization purposes, and have another property on the model that parses this to a `DateTime` \ `DateTimeOffset` to work with.

---

<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:** [November 14, 2021, 11:29pm UTC](https://discuss.elastic.co/t/elasticsearch-nest-query-returning-null-values-for-every-field/284796/3 "2021-11-14T23:29:10Z")

</div>

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