简体   繁体   English

从solr获取数据时,我遇到了错误

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

while getting data from solr, i am having the error blow 从solr获取数据时,我遇到了错误

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 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; }

   ...

In your SolrContent.cs class you have added the SolrUniqueKey attribute to the ContentId property that maps to the ContentId field in your schema. 在SolrContent.cs类中,您已将SolrUniqueKey属性添加到ContentId属性,该属性映射到架构中的ContentId字段。 This is therefore, stating that the ContentId field in the Solr index will always contain a unique value. 因此,这表明Solr索引中的ContentId字段将始终包含唯一值。 However, your index currently has multiple items with the same ContentId value. 但是,您的索引当前有多个具有相同ContentId值的项目。 There are a couple of ways around this error. 有两种方法可以解决此错误。

  1. Change the attribute on ContentId property to be just [SolrField("ContentId")] 将ContentId属性的属性更改为仅[SolrField("ContentId")]
  2. Fix your index so that the ContentId field only contains unique values. 修正索引,使ContentId字段仅包含唯一值。

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. 但是,您可以尝试第一个,只是为了验证您可以查询Solr索引而不会出现错误,然后弄清楚索引中的多个项目如何具有相同的ContentId以及解决该问题的方法。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

相关问题 将数据表中的数据放入图表时出现此错误 - I am getting this error while placing data from data table into chart 插入SQL时出现错误 - I am getting error while inserting to SQL 导出到 Excel 时出现错误 - I am getting an error while exporting to Excel 使用iTextSharp从PDF文件提取文本时,出现此错误:“找不到图像数据或EI” - While extracting text from PDF file using iTextSharp, I am getting this error: “Could not find image data or EI” 生成对象时出现错误 - I am getting an error while producing objects 删除文件时出现错误 - while deleting a file i am getting error 使用iTextSharp从PDF文件提取文本时,出现此错误:“找不到图像数据或EI” - While extracting text from PDF file using iTextSharp, I am getting this error: “Could not find image data or EI” 将数据上传到本地数据库时,出现一个错误,提示“对象必须实现可转换” - While uploading data to my local database i am getting an error called “Object must implement convertible” 为什么在尝试从XML文件读取数据时出现Null Referenfe异常? - Why am I getting Null Referenfe exception while trying to read data from XML file? 我无法从 angular/typscript 前端和 asp.net 后端的发布请求返回数据 - I am having trouble getting data returned from a post request in angular/typscript frontnend and asp.net backend
 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM