# Elasticsearch.Net, strange deserialization after .Index

**URL:** <https://discuss.elastic.co/t/elasticsearch-net-strange-deserialization-after-index/19817>\
**Category:** Elasticsearch\
**Created:** [September 16, 2014, 2:43pm UTC](https://discuss.elastic.co/t/elasticsearch-net-strange-deserialization-after-index/19817 "2014-09-16T14:43:54Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![lasseschou](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/lasseschou/32/845_2.png) [@lasseschou](https://discuss.elastic.co/u/lasseschou)\
**Post date:** [September 16, 2014, 2:43pm UTC](https://discuss.elastic.co/t/elasticsearch-net-strange-deserialization-after-index/19817/1 "2014-09-16T14:43:54Z")

</div>

Hi,

(let me know if this is not the right place to post [ElasticSearch.Net](http://ElasticSearch.Net)  
questions).

I'm indexing a document of type "User" through [ElasticSearch.Net](http://ElasticSearch.Net) with this  
command (key is a string guid):

client.Index(index, "user", key, user);

This invokes the serializer and stores the json in my ES cluster, as  
expected. ElasticSearch responds with this json:

{  
"\_index":"users\_2014\_09","\_type":"user","\_id":"M8k\_6WLTtESlYod8-CDUXw\_P4wXE0OkkvprjRiqGP1bqQ","\_version":1,"created":true}

Now the strange thing is that the [ElasticSearch.Net](http://ElasticSearch.Net) client tries to  
deserialize this result as a "User" object. Normally this deserialization  
method will return null and not create any visible side-effects, but in my  
case I'm using the field "created" as a DateTime field, and the  
deserialization throws a nasty error.

My question is: Why on earth does the client spend energy deserializing a  
response to an Index command, and into the wrong type? This looks like a  
bug.

Thanks,  
Lasse

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/1bfff890-ae3d-422f-b12b-54548cf01f62%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/1bfff890-ae3d-422f-b12b-54548cf01f62%40googlegroups.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![Itamar\_Syn\_Hershko](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/itamar_syn_hershko/32/725_2.png) [@Itamar\_Syn\_Hershko](https://discuss.elastic.co/u/Itamar_Syn_Hershko)\
**Post date:** [September 29, 2014, 4:23pm UTC](https://discuss.elastic.co/t/elasticsearch-net-strange-deserialization-after-index/19817/2 "2014-09-29T16:23:51Z")

</div>

This is probably a bug of the .NET client API, and you should log it on  
github where they monitor issues for it

You might find this alternative library useful:  
[GitHub - synhershko/NElasticsearch: An alternative Elasticsearch client for .NET, built on-the-go while working on real-world projects](https://github.com/synhershko/NElasticsearch) available from nuget as well  
[NuGet Gallery | NElasticsearch 1.0.15](https://www.nuget.org/packages/NElasticsearch/)

--

Itamar Syn-Hershko  
[http://code972.com](http://code972.com) | @synhershko [https://twitter.com/synhershko](https://twitter.com/synhershko)  
Freelance Developer & Consultant  
Author of RavenDB in Action [http://manning.com/synhershko/](http://manning.com/synhershko/)

On Tue, Sep 16, 2014 at 5:43 PM, Lasse Schou [lasseschou@gmail.com](mailto:lasseschou@gmail.com) wrote:

> Hi,
> 
> (let me know if this is not the right place to post [ElasticSearch.Net](http://ElasticSearch.Net)  
> questions).
> 
> I'm indexing a document of type "User" through [ElasticSearch.Net](http://ElasticSearch.Net) with this  
> command (key is a string guid):
> 
> client.Index(index, "user", key, user);
> 
> This invokes the serializer and stores the json in my ES cluster, as  
> expected. Elasticsearch responds with this json:
> 
> {  
> "\_index":"users\_2014\_09","\_type":"user","\_id":"M8k\_6WLTtESlYod8-CDUXw\_P4wXE0OkkvprjRiqGP1bqQ","\_version":1,"created":true}
> 
> Now the strange thing is that the [ElasticSearch.Net](http://ElasticSearch.Net) client tries to  
> deserialize this result as a "User" object. Normally this deserialization  
> method will return null and not create any visible side-effects, but in my  
> case I'm using the field "created" as a DateTime field, and the  
> deserialization throws a nasty error.
> 
> My question is: Why on earth does the client spend energy deserializing a  
> response to an Index command, and into the wrong type? This looks like a  
> bug.
> 
> Thanks,  
> Lasse
> 
> --  
> You received this message because you are subscribed to the Google Groups  
> "elasticsearch" group.  
> To unsubscribe from this group and stop receiving emails from it, send an  
> email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
> To view this discussion on the web visit  
> [https://groups.google.com/d/msgid/elasticsearch/1bfff890-ae3d-422f-b12b-54548cf01f62%40googlegroups.com](https://groups.google.com/d/msgid/elasticsearch/1bfff890-ae3d-422f-b12b-54548cf01f62%40googlegroups.com)  
> [https://groups.google.com/d/msgid/elasticsearch/1bfff890-ae3d-422f-b12b-54548cf01f62%40googlegroups.com?utm\_medium=email&utm\_source=footer](https://groups.google.com/d/msgid/elasticsearch/1bfff890-ae3d-422f-b12b-54548cf01f62%40googlegroups.com?utm_medium=email&utm_source=footer)  
> .  
> For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

--  
You received this message because you are subscribed to the Google Groups "elasticsearch" group.  
To unsubscribe from this group and stop receiving emails from it, send an email to [elasticsearch+unsubscribe@googlegroups.com](mailto:elasticsearch+unsubscribe@googlegroups.com).  
To view this discussion on the web visit [https://groups.google.com/d/msgid/elasticsearch/CAHTr4ZtJwbts5%2BTCCYE-dkPLzDTG8ZQjazUEcYeZxh9ePc08JQ%40mail.gmail.com](https://groups.google.com/d/msgid/elasticsearch/CAHTr4ZtJwbts5%2BTCCYE-dkPLzDTG8ZQjazUEcYeZxh9ePc08JQ%40mail.gmail.com).  
For more options, visit [https://groups.google.com/d/optout](https://groups.google.com/d/optout).

---

<div class="post-metadata">

**Author:** ![scamire](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/scamire/32/1077_2.png) [@scamire](https://discuss.elastic.co/u/scamire)\
**Post date:** [November 5, 2014, 10:25pm UTC](https://discuss.elastic.co/t/elasticsearch-net-strange-deserialization-after-index/19817/3 "2014-11-05T22:25:50Z")

</div>

This is because when using [Elasticsearch.NET](http://Elasticsearch.NET), specifying the type like that is actually specifying what type the expected response should be serialized into, rather than the type of object you're sending to Elasticsearch.

Drop the type completely and client.Index should return a ElasticsearchResponse object type.

See this link for details:  
[http://nest.azurewebsites.net/elasticsearch-net/handling-responses.html](http://nest.azurewebsites.net/elasticsearch-net/handling-responses.html)

Hope this 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:** [July 6, 2017, 12:51am UTC](https://discuss.elastic.co/t/elasticsearch-net-strange-deserialization-after-index/19817/4 "2017-07-06T00:51:59Z")

</div>


