# Not able to map Fields in NestedModel in Nest Search API

**URL:** <https://discuss.elastic.co/t/not-able-to-map-fields-in-nestedmodel-in-nest-search-api/198500>\
**Category:** Elasticsearch\
**Created:** [September 7, 2019, 8:58am UTC](https://discuss.elastic.co/t/not-able-to-map-fields-in-nestedmodel-in-nest-search-api/198500 "2019-09-07T08:58:49Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![vikasnew](https://avatars.discourse-cdn.com/v4/letter/v/bcef8e/32.png) [@vikasnew](https://discuss.elastic.co/u/vikasnew)\
**Post date:** [September 7, 2019, 8:58am UTC](https://discuss.elastic.co/t/not-able-to-map-fields-in-nestedmodel-in-nest-search-api/198500/1 "2019-09-07T08:58:50Z")

</div>

Hello,

i am facing issue while getting data from elasticsearch. i am using NEST client version 7.3.

i have my data stored in elasticsearch in following format:

```auto
{
 "_index": "custom-index-dev",
 "_type": "logevent",
 "_id": "VJcPBm0BVa5zJPTZuwbI",
 "_version": 1,
 "_score": 0,
 "_source": {
   "@timestamp": "2019-09-06T15:42:35.4110845+05:30",
   "level": "Information",
   "messageTemplate": "{HostingRequestStartingLog:l}",
   "message": "Request starting HTTP/1.1 POST http://localhost:5050/req/negotiate 0",
   "fields": {
               "Protocol": "HTTP/1.1",
               "Method": "POST",
               "Scheme": "http",
               "Host": "localhost:5050",
               "EventId": {
                            "Id": 1
                           },
               "RequestId": "0HLPIMAUEFD65:00000001",
               "RequestPath": "/req/negotiate",
               "ConnectionId": "0HLPIMAUEFD65",
               "Application": "Test"
   },
   "renderings": {
     "HostingRequestStartingLog": [
       {
         "Format": "l",
         "Rendering": "Request starting HTTP/1.1 POST http://localhost:5050/req/negotiate 0"
       }
     ]
   }
 },
 "fields": {
   "@timestamp": [
     "2019-09-06T10:12:35.411Z"
   ]
 }
}

```

And i am accessing the same data in .Net Core using NEST client as below

```auto
       var node = new Uri("http://localhost:9200");
        var settings = new ConnectionSettings(node);
        settings.DefaultIndex("custom-index-dev");
        var client = new ElasticClient(settings);

        var searchResponse = await client.SearchAsync<SearchResponse>(s => s
             .From(0)
             .Size(50)
         );

```

And "SearchResponse" Model is a nested model which has Fields model init.

```auto
    public class SearchResponse
    {
        public string Level { get; set; }
        public DateTime Time { get; set; }
        public string MessageTemplate { get; set; }
        public Fields Fields { get; set; }
    }

public class Fields
    {
        public EventId EventId { get; set; }
        public string Host { get; set; }
        public string TransportConnectionId { get; set; }
        public string RequestId { get; set; }
        public string RequestPath { get; set; }        
        public string ConnectionId { get; set; }
        public string Application { get; set; }
    }

public class EventId
    {
        public int Id { get; set; }
    }

```

But i am not able to get fields data int my inner model. Though i am able to get data in "SearchResponse" model but not in "Fields" Model init.

Please suggest..

Thanks in anticipation

---

<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:** [September 13, 2019, 9:08am UTC](https://discuss.elastic.co/t/not-able-to-map-fields-in-nestedmodel-in-nest-search-api/198500/2 "2019-09-13T09:08:58Z")

</div>

NEST 7.x expects the case of fields in JSON to match exactly the case in the client configuration; by default, the client expects camel cased field names, but this can be changed with

```auto
var settings = new ConnectionSettings()
    // example: upper case all field names
    .DefaultFieldNameInferrer(f => f.toUpperInvariant());

```

This is a **global** change however, and you have mixed casing in your documents, some camel cased and some pascal cased. In this scenario, you can explicitly map property names using [`DataMemberAttribibute` or `PropertyNameAttribute`](https://www.elastic.co/guide/en/elasticsearch/client/net-api/7.x/field-inference.html#field-name-attribute)

```auto
public class Fields
    {
        [DataMember(Name = nameof(EventId))]
        public EventId EventId { get; set; }
        [DataMember(Name = nameof(Host))]
        public string Host { get; set; }
        [DataMember(Name = nameof(TransportConnectionId))]
        public string TransportConnectionId { get; set; }
        [DataMember(Name = nameof(RequestId))]
        public string RequestId { get; set; }
        [DataMember(Name = nameof(RequestPath))]
        public string RequestPath { get; set; }
        [DataMember(Name = nameof(ConnectionId))]        
        public string ConnectionId { get; set; }
        [DataMember(Name = nameof(Application))]
        public string Application { get; set; }
    }

```

---

<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:** [October 11, 2019, 9:09am UTC](https://discuss.elastic.co/t/not-able-to-map-fields-in-nestedmodel-in-nest-search-api/198500/3 "2019-10-11T09:09:01Z")

</div>

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