# Mapping elastic query response to POCOs in NEST

**URL:** https://discuss.elastic.co/t/mapping-elastic-query-response-to-pocos-in-nest/355458
**Category:** Elasticsearch
**Tags:** language-clients
**Created:** [March 15, 2024, 9:18am UTC](https://discuss.elastic.co/t/mapping-elastic-query-response-to-pocos-in-nest/355458 "2024-03-15T09:18:15Z")
**Posts on this page:** 2
**Page:** 1

<div class="post-metadata">

### Author: ![Daniel\_Makos](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/daniel_makos/32/132622_2.png) [@Daniel\_Makos](https://discuss.elastic.co/u/Daniel_Makos)
#### Post date: [March 15, 2024, 9:18am UTC](https://discuss.elastic.co/t/mapping-elastic-query-response-to-pocos-in-nest/355458/1 "2024-03-15T09:18:15Z")

</div>

Following up on this question here: [How to map C# DateTime property to @timestamp field](https://discuss.elastic.co/t/how-to-map-c-datetime-property-to-timestamp-field/327866)  
I initialize the Elastic connection:

```auto
ElasticsearchClientSettings settings;
            using (settings = new ElasticsearchClientSettings(new Uri($"{configOptions.Url}")))
            {
                settings = settings
                    .Authentication(authentication)
                    .DefaultIndex("filebeat-*-app-logs-*");
                Client = new ElasticsearchClient(settings);

                Client.ElasticsearchClientSettings.PropertyMappings
                    .Add(typeof(Audit).GetMember("Timestamp")[0], new PropertyMapping() { Name = "@timestamp" });
            }

```

My query

```auto
            var searchResponse = await _client.Client.SearchAsync<T>(s => s
               .Query(q => q
                    .MatchPhrase(m => m
                        .Field("fields.ThermostatId")
                        .Query("some-guid-here"))));

```

is able to map data to some of the Properties, namely to the text types Message and Level, all the others stay default initialized.

```auto
public class Audit
    {
        [Keyword(Name = "_id")]
        public Guid Id { get; set; }

        [Date(Name = "@timestamp")]
        public DateTime Timestamp { get; set; }

        [Keyword(Name = "level")]
        public string Level { get; set; }

        [Keyword(Name = "Message")]
        public string Message { get; set; }

        [Nested]
        public ThermostatLog Fields { get; set; }

```

I tried manually mapping in the config but it doesn't make any difference. The annotiation in the entity class is not proven to be enough.

---

<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: [April 12, 2024, 9:18am UTC](https://discuss.elastic.co/t/mapping-elastic-query-response-to-pocos-in-nest/355458/2 "2024-04-12T09:18:27Z")

</div>

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