# Create C# Class from existing Index

**URL:** <https://discuss.elastic.co/t/create-c-class-from-existing-index/223138>\
**Category:** Elasticsearch\
**Tags:** language-clients\
**Created:** [March 11, 2020, 1:04pm UTC](https://discuss.elastic.co/t/create-c-class-from-existing-index/223138 "2020-03-11T13:04:29Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![Michal\_Svacina](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/michal_svacina/32/64230_2.png) [@Michal\_Svacina](https://discuss.elastic.co/u/Michal_Svacina)\
**Post date:** [March 11, 2020, 1:04pm UTC](https://discuss.elastic.co/t/create-c-class-from-existing-index/223138/1 "2020-03-11T13:04:29Z")

</div>

Hello,

I am pretty new to working with Elasticsearch. Right now I am trying to query some data from Elastic 6.5 with .net client NEST.

So I have existing index that I want to search In. I tried to create the C# class myself or with auto-generator QuickType.

Unfortunatelly with both approaches I can have something come back from Elastic but it never gets mapped on the properties it should.

I can get back 10 hits but most of the parameters are null except Counts and ID which match to the document ID in elastic.

So from that I know my configuration and connection works fine. But i think that the problem is with my class that is most likely bad.

When i open the JSON of document in Kibana it looks like this (some of the data is deleted):

```
{
  "_index": "",
  "_type": "_doc",
  "_id": "B1wPn3ABHLnBb2g1j46j",
  "_version": 1,
  "_score": null,
  "_source": {
    "some_identifier": "[ner#3-44-C-1] ",
    "severity": "",
    "matching_rule": "",
    "escalation_type": "INCIDENT",
    "contractId": "null",
    "sid": "",
    "@timestamp": "2020-03-03T06:22:41.980Z",
    "escalation_time": "07:22:41.100",
    "@version": "1",
    "message": "",
    "parameters": "",
    "userId": "null",
    "host": "",
    "path": "/srv/log/"
  },
  "fields": {
    "@timestamp": [
      "2020-03-03T06:22:41.980Z"
    ]
  },
  "sort": [
    1583216561980
  ]
}

```

How should I create the class so it works?

---

<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:** [March 12, 2020, 7:06am UTC](https://discuss.elastic.co/t/create-c-class-from-existing-index/223138/2 "2020-03-12T07:06:46Z")

</div>

You only need to create a class for the `_source`, something like the following should work

```
public class MyDocument
{
    [PropertyName("some_identifier")]
    public string SomeIdentifier { get; set; }

    [PropertyName("severity")]
    public string Severity { get; set; }

    [PropertyName("matching_rule")]
    public string MatchingRule { get; set; }

    [PropertyName("escalation_type")]
    public string EscalationType { get; set; }

    [PropertyName("contractId")]
    public string ContractId { get; set; }

    [PropertyName("sid")]
    public string Sid { get; set; }

    [PropertyName("@timestamp")]
    public DateTimeOffset Timestamp { get; set; }

    [PropertyName("escalation_time")]
    public DateTimeOffset EscalationTime { get; set; }

    [PropertyName("@version")]
    public string Version { get; set; }

    [PropertyName("message")]
    public string Message { get; set; }

    [PropertyName("parameters")]
    public string Parameters { get; set; }

    [PropertyName("userId")]
    public string UserId { get; set; }

    [PropertyName("host")]
    public string Host { get; set; }

    [PropertyName("path")]
    public string Path { get; set; }
}
```

---

<div class="post-metadata">

**Author:** ![Michal\_Svacina](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/michal_svacina/32/64230_2.png) [@Michal\_Svacina](https://discuss.elastic.co/u/Michal_Svacina)\
**Post date:** [March 12, 2020, 7:14am UTC](https://discuss.elastic.co/t/create-c-class-from-existing-index/223138/3 "2020-03-12T07:14:08Z")

</div>

Thank you so much.

I feel a bit stupid I did not try that.

---

<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:** [March 12, 2020, 7:14am UTC](https://discuss.elastic.co/t/create-c-class-from-existing-index/223138/4 "2020-03-12T07:14:46Z")

</div>

No worries, hope it helps!

---

<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 9, 2020, 7:14am UTC](https://discuss.elastic.co/t/create-c-class-from-existing-index/223138/5 "2020-04-09T07:14:49Z")

</div>

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