# Elasticsearch.Net deserialize to my type

**URL:** <https://discuss.elastic.co/t/elasticsearch-net-deserialize-to-my-type/97418>\
**Category:** Elasticsearch\
**Created:** [August 17, 2017, 1:04pm UTC](https://discuss.elastic.co/t/elasticsearch-net-deserialize-to-my-type/97418 "2017-08-17T13:04:44Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![Karolinebryn](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/karolinebryn/32/17095_2.png) [@Karolinebryn](https://discuss.elastic.co/u/Karolinebryn)\
**Post date:** [August 17, 2017, 1:04pm UTC](https://discuss.elastic.co/t/elasticsearch-net-deserialize-to-my-type/97418/1 "2017-08-17T13:04:44Z")

</div>

According to the documentation on [Elasticsearch.Net](https://www.elastic.co/guide/en/elasticsearch/client/net-api/1.x/handling-responses.html#_typed_api_calls) you can provide your own type that [Elasticsearch.Net](http://Elasticsearch.Net) will deserialize into, like this:

`ElasticsearchLowLevelClient.Index<MyCustomType>(indexName, type, id, obj);`

Which only works if the type is defined like this:

```
public class ElasticsearchResult
    {
        public string _index { get; set; }
        public string _type { get; set; }
        public string _id { get; set; }
        public int _version { get; set; }
        public string result { get; set; }
        public Shard _shards { get; set; }
        public bool created { get; set; }
    }

```

But I want this type to look like this:

```
public class ElasticsearchResult
    {
        public string Index { get; set; }
        public string Type { get; set; }
        public string Id { get; set; }
        public int Version { get; set; }
        public string Result { get; set; }
        public Shard Shards { get; set; }
        public bool Created { get; set; }
    }

```

How do I achieve that? I have tried to use the JsonProperty attribute `[JsonProperty(PropertyName = "_shards")]`, but that does not work.

---

<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:** [August 23, 2017, 10:27am UTC](https://discuss.elastic.co/t/elasticsearch-net-deserialize-to-my-type/97418/2 "2017-08-23T10:27:12Z")

</div>

The low level client has no dependency on [JSON.Net](http://JSON.Net), so `JsonProperty` attributes will not work. It has a simple JSON serializer.

I'd strongly recommend going with NEST, the high level client for cases like this. NEST internally uses [JSON.Net](http://JSON.Net), so does understand `JsonProperty` attributes, although you probably don't need them as known response values are already mapped by NEST to strong types.

In using NEST, you also have access to the low level client in cases where you want to use it, through the `.LowLevel` property on the high level client. An advantage here is that the low level client will also use the internal serializer that uses [JSON.Net](http://JSON.Net) so attributes will work, as well as returning strongly typed NEST responses from low level calls. [Check out the note in the Getting Started "Search" section of the documentation.](https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/nest-getting-started.html#_searching_2)

---

<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:** [September 20, 2017, 10:27am UTC](https://discuss.elastic.co/t/elasticsearch-net-deserialize-to-my-type/97418/3 "2017-09-20T10:27:22Z")

</div>

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