1

When I run this code:

var result = _client.Index<EntityType>(item, i => i.Index(n));

I'm getting this error:

Exception has occurred: CLR/System.StackOverflowException An unhandled exception of type 'System.StackOverflowException' occurred in Elasticsearch.Net.dll

The full method:

public bool Index<EntityType>(EntityType item, int attempt = 0) where EntityType : class, IDomainEntity<int>
{
    const int maxRetries = 5;
    if (item == null)
    {
        return false;
    }
    var type = item.GetType();
    var attributes = type.CustomAttributes;
    string n = "";

    foreach (var attribute in attributes)
    {
        foreach (var arg in attribute.NamedArguments)
        {
            if (arg.MemberName == "RelationName")
            {
                n = arg.TypedValue.Value.ToString().ToLower();
            }
        }
    }

    var result = _client.Index<EntityType>(item, i => i.Index(n));
    if (!CheckResponse(result) && attempt < maxRetries)
    {
        RefreshClient<EntityType>();
        attempt++;
        return Index(item, attempt);
    }
    RefreshClient<EntityType>();
    return result.IsValid;
}
8
  • What is IdType of property Id? Commented May 19, 2021 at 17:08
  • @RussCam int. I use a generic for allowing string id's too. Commented May 19, 2021 at 20:08
  • Ah sorry, I missed that (late late night :)) Do you have a complete reproducible example that can be shared (here or as a gist)? Commented May 19, 2021 at 23:10
  • @RussCam I actually think it might be the same as your other answer, I had linked that in my question before realising you had answered it. Commented May 20, 2021 at 6:54
  • That's my suspicion too Commented May 20, 2021 at 10:31

1 Answer 1

1

I added [PropertyName("propertyToIgnoreInElasticsearch", Ignore = true)] from NEST to my POCO fields which were causing an infinite loop while Indexing. It ignores a field from the Elasticsearch Index so it is not indexed.

for example:

[Serializable]
public abstract class VeganItem<VeganItemEstablishmentType>
{
    [Required]
    public string Name { get; set; }

    [PropertyName("veganItemEstablishments", Ignore = true)]
    public virtual ICollection<VeganItemEstablishmentType> VeganItemEstablishments { get; set; }
}
Sign up to request clarification or add additional context in comments.

1 Comment

I'm glad to see you got it sorted. In general, it's better to create specific POCOs for interacting with Elasticsearch. Complex objects such as those used with ORMs like Entity Framework and NHibernate that can include lazily loaded entities and self-referencing loops can cause problems when serializing to JSON, to send to Elasticsearch

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.