[C# NEST] Query results with special characters not mapping properly

When performing queries on indices that have field names with special characters, they are not correctly mapped to the provided model.

Example index:

{
        "_index" : "my-index-with-special-characters",
        "_id" : "20.20.20.15",
        "_score" : 1.0,
        "_source" : {
            "host.ip" : "20.20.20.15",
            ....
}

Example model:

public class myModel {
    [JsonPropertyName("host.ip")]
    public string HostIp { get; set; }
}

Example query:

var esAssets = ElasticAuth.Client("my-index-with-special-characters")
               .Search<myModel>(s => s
                   .From(0)
                   .Size(10000)
                   .MatchAll()
               );

There are several fields in this index that do not have the "." character that map correctly, but each one that has the dot character does no map at all.

Is there a special way this case needs to be handled?

Thank you!

I seemed to have found an answer. Declaring a Nest.PropertyName above each field with a special character seems to do the trick.

[Nest.PropertyName("host.ip")]
public string HostIp { get; set; }

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