我的java代码看起来像这样:
public class CreateSolr4Doc {
public static void main(String[] args) {
int recordCount = 3;
CreateSolr4Doc instance = new CreateSolr4Doc();
instance.createDummyData(recordCount);
}
private void createDummyData(int recordCount) {
String url = "http://localhost:8983/solr/collection1";
System.out.println(url);
HttpSolrServer solr = new HttpSolrServer(url);
for (int index = 0; index < recordCount; index++) {
for(int j=1;j<=20000;j++)
{
SolrInputDocument doc = new SolrInputDocument();
Date date = new Date();
doc.addField("id","ibsfdjkhfb"+index+j);
doc.addField("mongoid", "4eebb9db43d7391c16509153");
doc.addField("agency","AFP");
doc.addField("title","Masked men loot cash, cellphones"+(index+1));
doc.addField("story",(index+1) + "PATNA: Giving a damn to");
doc.addField("mimetype","TEXT");
doc.addField("subject","The criminals first reached the office-cum")
doc.addField("coverage","patna");
doc.addField("isSyndicated",1);
doc.addField("createdDate",org.apache.commons.lang.time.DateUtils.addDays(date, -(index+101)));
doc.addField("expiryDate","2061-12-17T03:06:13Z");
doc.addField("language","en");
doc.addField("version","1.0");
doc.addField("ingestionDate","2011-12-16T21:36:28.296Z");
doc.addField("ingestionDate_index","2011-12-17T03:06:00Z");
System.out.println("Inserting document"+" "+(j)+" "+(index+1));
try {
solr.add(doc);
} catch (SolrServerException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
try {
UpdateResponse response = solr.commit();
System.out.println(response);
} catch (SolrServerException e) {
e.printStackTrace();
} catch (IOException e) {
e.printStackTrace();
}
}
}
}
当我插入数据时,我收到如下错误消息: -
插入文件1 1
线程“main”中的异常org.apache.solr.common.SolrException:错误:[doc = ibsfdjkhfb01] unknown field'mongoid'
我在文档中添加字段时遇到错误。 我不知道该怎么办。
答案 0 :(得分:0)
根据错误消息,您似乎有一个不在架构中的字段。尝试将mongoid添加到schema.xml中,看看是否有帮助。