# Nest 6 JSonConverters

**URL:** <https://discuss.elastic.co/t/nest-6-jsonconverters/151016>\
**Category:** Elasticsearch\
**Created:** [October 4, 2018, 9:55am UTC](https://discuss.elastic.co/t/nest-6-jsonconverters/151016 "2018-10-04T09:55:37Z")\
**Posts on this page:** 5\
**Page:** 1

<div class="post-metadata">

**Author:** ![bert\_vervaele](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bert_vervaele/32/36142_2.png) [@bert\_vervaele](https://discuss.elastic.co/u/bert_vervaele)\
**Post date:** [October 4, 2018, 9:55am UTC](https://discuss.elastic.co/t/nest-6-jsonconverters/151016/1 "2018-10-04T09:55:37Z")

</div>

Hi,

we are upgrading our Elastic from 5.2.2 to 6.2.1 but we have a problem with our search requests.  
We use nest to communicate with our code. We use JSonConverters in our customserialization to read jsons and convert them to objects. With the 5.2.2 driver we could easily access the indexname with from the JsonReader.

In 5.2.2 we could cast the JSonReader to JTokenReader and call something like "reader.CurrentToken.Parent["\_index"], but now this has become a JSonTextReader which, if i am not mistaking, makes it impossible to call the parent, we can only access the source.

Is there a way to get the index back in the response in our JSonConverter?

Kind regards Bert

---

<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:** [October 14, 2018, 7:16pm UTC](https://discuss.elastic.co/t/nest-6-jsonconverters/151016/2 "2018-10-14T19:16:37Z")

</div>

Would you mind showing an example of what you're doing in 5.x?

---

<div class="post-metadata">

**Author:** ![bert\_vervaele](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/bert_vervaele/32/36142_2.png) [@bert\_vervaele](https://discuss.elastic.co/u/bert_vervaele)\
**Post date:** [October 25, 2018, 8:57am UTC](https://discuss.elastic.co/t/nest-6-jsonconverters/151016/3 "2018-10-25T08:57:17Z")

</div>

Hi this is the code we used.  
It basicly got the index name out of our response.

> Blockquote  
> private string GetTableNameFromRequest(JsonReader reader)  
> {  
> var realReader = reader as JTokenReader;  
> if (realReader != null)  
> {  
> var index = realReader.CurrentToken.Parent.Parent["\_index"].ToString();  
> if (!index.StartsWith(IndexBaseName)) return null;  
> var endString = index.Substring(IndexBaseName.Length + 1);  
> if (endString.StartsWith(ElasticLoggerTableData.IndexPrefix))  
> {  
> endString = endString.Substring(ElasticLoggerTableData.IndexPrefix.Length + 1);  
> }  
> return endString.Split('-')[0];  
> }  
> return null;  
> }

---

<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:** [October 26, 2018, 3:15am UTC](https://discuss.elastic.co/t/nest-6-jsonconverters/151016/4 "2018-10-26T03:15:46Z")

</div>

I can't see an easy way of doing this with 6.x by navigating up the AST from `_source` inside of the `SourceSerializer`, as the serializer is passed only the stream containing the `_source` JSON when using your own configured `SourceSerializer` such as [`JsonNetSerializer`](https://www.elastic.co/guide/en/elasticsearch/client/net-api/current/custom-serialization.html#_jsonnetserializer).

Would using `SearchResponse.Hits` that exposes the `_index` along with each `_source` document work?

> <https://github.com/elastic/elasticsearch-net/blob/3bde31718b7371c798b7829f8fc2040e0f5f3a55/src/Nest/Search/Search/SearchResponse.cs#L159-L160>

---

<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:** [November 23, 2018, 3:29am UTC](https://discuss.elastic.co/t/nest-6-jsonconverters/151016/5 "2018-11-23T03:29:18Z")

</div>

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