品优购solr报错Document is missing mandatory uniqueKey field: id

报错

Exception in thread "main" org.springframework.data.solr.UncategorizedSolrException: Document is missing mandatory uniqueKey field: id; nested exception is org.apache.solr.client.solrj.impl.HttpSolrServer$RemoteSolrException: Document is missing mandatory uniqueKey field: id
	at org.springframework.data.solr.core.SolrTemplate.execute(SolrTemplate.java:145)
	at org.springframework.data.solr.core.SolrTemplate.saveBean(SolrTemplate.java:184)
	at org.springframework.data.solr.core.SolrTemplate.saveBean(SolrTemplate.java:178)
	at com.pinyougou.solrutil.SolrUtil.importItemData(SolrUtil.java:35)
	at com.pinyougou.solrutil.SolrUtil.main(SolrUtil.java:43)
Caused by: org.apache.solr.client.solrj.impl.HttpSolrServer$RemoteSolrException: Document is missing mandatory uniqueKey field: id
	at org.apache.solr.client.solrj.impl.HttpSolrServer.executeMethod(HttpSolrServer.java:552)
	at org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:210)
	at org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:206)
	at org.apache.solr.client.solrj.request.AbstractUpdateRequest.process(AbstractUpdateRequest.java:124)
	at org.apache.solr.client.solrj.SolrServer.add(SolrServer.java:116)
	at org.springframework.data.solr.core.SolrTemplate$4.doInSolr(SolrTemplate.java:187)
	at org.springframework.data.solr.core.SolrTemplate$4.doInSolr(SolrTemplate.java:184)
	at org.springframework.data.solr.core.SolrTemplate.execute(SolrTemplate.java:141)
	... 4 more

代码错误位置

错误代码位置

修正后代码

修正后代码位置

错误代码

solrTemplate.saveBean(itemList);

正确代码

solrTemplate.saveBeans(itemList);

总结

  • 粗心少写一个s
  • 因为代码提示直接依赖Tab键导致没再次审核
  • 代码逻辑导致代码不提示报错,以至于难以找到
  • 程序员以后需要多多细心
  • 找错找最后一个Caused by的报错内容, 简短关键字多

猜你喜欢

转载自blog.csdn.net/qq_36694268/article/details/84874498