[英]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. 有两种方法可以解决此错误。
[SolrField("ContentId")]
将ContentId属性的属性更改为仅[SolrField("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.