yuri
yuri

Reputation: 11

while getting data from solr, i am having the error blow

while getting data from solr, i am having the error blow

an item with the same key has already been added

    public  static void Solryeg()
    {
        ISolrOperations<SolrContent> solr = ServiceLocator.Current
                                  .GetInstance<ISolrOperations<SolrContent>>();

        var q = solr.Query(SolrQuery.All);
    }

SolrContent.cs

public class SolrContent
{
    [SolrUniqueKey("ContentId")]
    public int ContentId { get; set; }


    [SolrField("ContentName")]
    public string ContentName { get; set; }

    [SolrField("ContentTitle")]
    public string ContentTitle { get; set; }

    [SolrField("ContentIsActive")]
    public bool ContentIsActive { get; set; }

    [SolrField("ContentRatingEnabled")]
    public bool ContentRatingEnabled { get; set; }

   ...

Upvotes: 0

Views: 586

Answers (1)

Paige Cook
Paige Cook

Reputation: 22555

In your SolrContent.cs class you have added the SolrUniqueKey attribute to the ContentId property that maps to the ContentId field in your schema. This is therefore, stating that the ContentId field in the Solr index will always contain a unique value. However, your index currently has multiple items with the same ContentId value. There are a couple of ways around this error.

  1. Change the attribute on ContentId property to be just [SolrField("ContentId")]
  2. Fix your index so that the ContentId field only contains unique values.

I recommend you go with the 2nd option as this will follow the true intent of what you are trying to achieve. However, you might try the first one just to validate you can query the Solr index without the error and then figure out how your index has multiple items with the same ContentId and the fix that issue as well.

Upvotes: 1

Related Questions