品優購solr報錯Document is missing mandatory uniqueKey field: id
阿新 • • 發佈:2018-12-14
報錯
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的報錯內容, 簡短關鍵字多