簡體   English   中英

Spring Data + Solr 6.2

[英]Spring Data + Solr 6.2

我在Spring-Data + Solr6.x中有一個奇怪的行為。

1)Bean聲明

@Id
@Indexed(name=EventSchema.id) //I also try without this annotation
private String id;

2)回購

solrTemplate.saveBean(event);
solrTemplate.commit();

3)錯誤

org.springframework.data.solr.UncategorizedSolrException: Error from server at http://192.168.99.100:8983/solr/eventCore: Document is missing mandatory uniqueKey field: id; nested exception is org.apache.solr.client.solrj.impl.HttpSolrClient$RemoteSolrException: Error from server at http://192.168.99.100:8983/solr/eventCore: Document is missing mandatory uniqueKey field: id
at org.springframework.data.solr.core.SolrTemplate.execute(SolrTemplate.java:172) ~[spring-data-solr-2.0.6.RELEASE.jar:na]
at org.springframework.data.solr.core.SolrTemplate.saveBean(SolrTemplate.java:219) ~[spring-data-solr-2.0.6.RELEASE.jar:na]
at org.springframework.data.solr.core.SolrTemplate.saveBean(SolrTemplate.java:213) ~[spring-data-solr-2.0.6.RELEASE.jar:na]

從solr 5.x遷移到6.2(相同的sw代碼)后,將出現此異常。

如果document.id為null,如何在solr 6.2(或spring?)中強制生成ID?

要自動生成ID,您可以將其添加到您的solrconfig文件中

<updateRequestProcessorChain>
 <processor class="solr.UUIDUpdateProcessorFactory">
  <str name="fieldName">id</str>
 </processor>
 <processor class="solr.LogUpdateProcessorFactory" />
 <processor class="solr.RunUpdateProcessorFactory" />
</updateRequestProcessorChain>

並且還必須在您的架構中添加ID字段和uniqueKey。

<uniqueKey>id</uniqueKey>

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM