1
votes

I'm using NEST lib, and very basic setup according to the document. I've added index, mapping, etc.

But when I try to do search it always gives me, "An item with the same key has already been added". It confused me alot on what the error means.

        var result = client.Search<Contact>(s => s
            .AllIndices()
            .From(0)
            .Size(10)
            .Query(q => q
                .MatchAll())
        );

Here is the Contact:

public class Contact
{
    public Guid Id { get; set; }
    public Guid TenantId { get; set; }
    public string Title { get; set; }
    public string FirstName { get; set; }
    public string LastName { get; set; }
    public DateTime ModifiedDate { get; set; }
    public IList<string> Emails { get; set; }
}
1
Are you sure this peace of code is causing error? Which version of ES, NEST do you sue?Rob
May you share Contact class as well?Rob
Rob, I'm using ES v1.5.2, NEST v1.5.0Fei
Your example is working like a charm with NEST 1.5.0. May you share more details?Rob
Rob, interesting that if I don't use any mapping it works fine, but after I put my custom mappings in it gives me that mysterious error, "An item with the same key has already been added".Fei

1 Answers

0
votes

You likely have a contact in elastic with the same email address twice. You could change the Email property to a string array perhaps?