ElasticSearch Nest query returning Null values for every field?

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 and c# - NEST returns null instead of fields - Stack Overflow but neither was able to help me fix the issue. This is my code - super basic:

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

.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?

The following exception

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

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.

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