I'm using the C# Elastic Nest client to retrieve the data from the Elasticsearch. I have created a POCO class named IndexModel which corresponds to the index mapping of my "testing-index" index. I get all the data from the index using this search method:
var result = client.Search<IndexModel>(s => s
.Index("testing-index")
.MatchAll());
However, I would like to be able to gather also the json data that didn't succeed to be mapped into any of the POCO properties, e.g. when the index mapping changes. I know that Nest uses Utf8Json as a Json serializer, but I couldn't find out if there is a possibility like in System.Text.Json.Serialization to add a data annotation above some dictionary that would catch all the overflow json data. Something like this?
[JsonExtensionData]
public Dictionary<string, object> ExtensionData { get; set; }
Or is there a possibility that the elastic client handles it and informs me somehow that some data didn't match any POCO properties?
There's no feature for this in the client.
The options are defining a POCO to represent the document, or using a type that can handle arbitrary JSON structures such as using
JsonNetSerializeralong withJObjectto represent documents.