Specifically, NEST can't figure out the right class to use and throws an exception:
Could not create an instance of type IMediaDetectionRole.
Type is an interface or abstract class and cannot be instantiated.
Path 'hits.hits[0]._source.roles[0].name', line 1, position 343.
I'm guessing your SO example is a simplified one? Otherwise you wouldn't need an interface at all.
You may be able to get around this using a custom JsonConverter over your Roles property. That would need to parse the json to some temp object, switch on the value of GetRoleType and hydrate and return the appropriate concrete object.
Or more simply, you could have just the one MediaDetectionRole class that you use with Elasticsearch, and expose a method like AsIMediaDetectionRole that does the switch for you after the fact.
Many thanks @KodrAus for your response and for steering me towards JSON.net for a solution and thanks to @Martijn_Laarman for showing me that I could resolve this issue using a [JsonProperty] attribute to force the rendering of Type information within the nested List.
Apache, Apache Lucene, Apache Hadoop, Hadoop, HDFS and the yellow elephant
logo are trademarks of the
Apache Software Foundation
in the United States and/or other countries.