0
votes

One of the fields in my elastic index is always deserialized as null by Nest. The index I am using has the following structure:

"myIndex": {
    "myMapping": {
      "name": {default properties},
      "guid": {"type": "keyword"},
      "myDisabledField": {
        "type": "object",
        "enabled": false
      }
    }
 }

When I try a search against this index using Nest 6.x, it always returns "myDisabledField" as null. However, if I make the same request in kibana it shows "myDisabledField" in the _source. For example, the kibana query:

GET myIndex/_search
{
  "query": {
    "query_string": {
      "query": "sample query"
    }
  }
}

would return the following:

{
  "hits": [
    { 
      "_index": "myIndex",
      "_source": {
        "name": "some_name",
        "guid": "some_guid",
        "myDisabledField": {
          "field1": "value1",
          "field2": "value2",
          ... etc
        }
      }
    }
  ]
}

However, the C#/Nest query:

var result = _elasticClient.Search<T>(
  s => s
  .Query(
    q => q
    .QueryString(
      qs => qs
      .Query("sample query")
    )
  )
);

return result.Documents.ToList();

Returns something like:

[
  "MyObject": {
    "Name": "some_name",
    "Guid": "some_guid",
    "MyDisabledField": null
  }
]

"MyObject" in this case is the POCO that I used to populate this index. How do I get Nest to fill "MyDisabledField" with the data stored in the _source? Is there some sort of setting needed to deserialize objects, or fields with the setting enabled=false?

By the way I used the DefaultMappingFor connection setting to map to the correct index for my type. This is the documentation on the enabled property I used

1
Please could you edit your question to include a small but complete example that reproduces what you're seeing? I can think of a few possible reasons why this might be the case, so a complete example would really help to quickly rule these out - Russ Cam
Thanks @RussCam. In my question I tried to provide an example, simplified with the details removed. Can you tell me what sort of information I am missing that would be helpful to you? - Pierce Mason
Thanks @RussCam. You asking for more information made me realize that I had not posted my model. Upon re-examining my model I realized that the setter was missing from the field in question. I just kept missing that earlier for some reason. Thanks for your help! - Pierce Mason
Glad you got it sorted @PierceMason! - Russ Cam

1 Answers

0
votes

The question as I posted it actually works. It turns out that I was missing the "setter" on the "MyDisabledField" C# property. So I had:

public class MyMapping{
  public string Name {get; set;}

  public string Guid {get; set;}

  public MyObject MyDisabledField {get; }
}

Instead of:

public class MyMapping{
  public string Name {get; set;}

  public string Guid {get; set;}

  public MyObject MyDisabledField {get; set;}
}

I was just blind for an afternoon. Sorry to waste everyone's time. Deserializing enabled=false objects works as you would expect