Nest 6 JSonConverters

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

1 Like

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

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;
}

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.

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

1 Like

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