Search code examples
c#azure-cognitive-searchazure-search-.net-sdk

How can I index a self-referential object?


For example, Exception contains a reference to itself inside Exception.InnerException. I have a class like this that I want to index but var fields = FieldBuilder.BuildForType<DTO>(); throws a StackoverflowException. How can I index this object?

So far my only idea is to put [FieldBuilderIgnore] on the reference and manually submit each object by crawling the the references but that doesn't sound right and I don't know what implications it would have on searchability.


Solution

  • You can't define a self-referential field in Azure Cognitive Search; There is no way to express such a field in the index definition. Complex fields in the index are defined by structure and not by type, so sub-field relationships imply containment rather than reference.