How to set the property on POCO for ElasticSearch NEST API to serialize it correctly

I have the below POCO for ElasticSearch response

 public PublicationInfo PublicationInfo { get; }

where the PublicationInfo is defined as below

public class PublicationInfo
    {
        public string Issn { get; }
        public string Volume { get; }
        public string Pagination { get;}
    }

The ElasticSearch mapping is as below

     "publicationinfo" : {
          "properties" : {
            "issn" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "pagination" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            },
            "volume" : {
              "type" : "text",
              "fields" : {
                "keyword" : {
                  "type" : "keyword",
                  "ignore_above" : 256
                }
              }
            }
          }
        }

When the search response is searialized to POCO, the PublicationInfo property is returned as null although the response has a value.

What needs to be done to have NEST serialize the response correctly to the PublicationInfo property?

ConnectionSettings are as below

var settings = new ConnectionSettings(pool)
                .DefaultIndex("indexname")
                .DefaultFieldNameInferrer(field => field.ToLower());

Using ElasticSearch v7.4 and NEST v7.4

The properties need a setter in order for the serializer to be able to set properties on them.

Many thanks. I was sure I was missing something obvious. :slight_smile:

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