Java helloword solj程序给了我一个例外';错误请求';
我试图从java应用程序中用solr索引这些数据 问题是它给了我这个例外Java helloword solj程序给了我一个例外';错误请求';,java,solr,solrj,Java,Solr,Solrj,我试图从java应用程序中用solr索引这些数据 问题是它给了我这个例外 Exception in thread "main" org.apache.solr.common.SolrException: Bad Request Bad Request request: http://localhost:8983/solr/update?wt=javabin&version=2 at org.apache.solr.client.solrj.impl.CommonsHttpSo
Exception in thread "main" org.apache.solr.common.SolrException: Bad Request
Bad Request
request: http://localhost:8983/solr/update?wt=javabin&version=2
at org.apache.solr.client.solrj.impl.CommonsHttpSolrServer.request(CommonsHttpSolrServer.java:436)
at org.apache.solr.client.solrj.impl.CommonsHttpSolrServer.request(CommonsHttpSolrServer.java:246)
at org.apache.solr.client.solrj.request.AbstractUpdateRequest.process(AbstractUpdateRequest.java:104)
at org.apache.solr.client.solrj.SolrServer.add(SolrServer.java:70)
at org.apache.solr.client.solrj.SolrServer.add(SolrServer.java:55)
at com.gismo.ReadFromSolr.main(ReadFromSolr.java:47)
这是我的密码
public static void main(String[] args) throws SolrServerException, SQLException, IOException
{ String url = "http://localhost:8983/solr/db";
CommonsHttpSolrServer solrServer = new
CommonsHttpSolrServer("http://localhost:8983/solr");
SolrInputDocument doc1 = new SolrInputDocument();
doc1.addField( "pk_id", "id1");
doc1.addField("doc_type", "content");
doc1.addField( "id", "1");
doc1.addField( "content_text", "hello world" );
Collection<SolrInputDocument> docs = new
ArrayList<SolrInputDocument>();
docs.add(doc1);
solrServer.add(docs);
solrServer.commit();
}
publicstaticvoidmain(字符串[]args)抛出SolrServerException、SQLException、IOException
{字符串url=”http://localhost:8983/solr/db";
CommonHttpSolrServer solrServer=新建
CommonHttpSolrServer(“http://localhost:8983/solr");
SolrInputDocument doc1=新的SolrInputDocument();
doc1.addField(“pk_id”、“id1”);
doc1.addField(“doc_type”、“content”);
doc1.添加字段(“id”、“1”);
doc1.addField(“content_text”,“hello world”);
收款单据=新单据
ArrayList();
docs.add(doc1);
solrServer.add(文档);
提交();
}
我还有一个问题
1。我是否需要在索引之前在某处声明此字段:例如在solr中
C:\solr-4.1.0\example\solr\collection1\conf\schema.xml是的,您需要确保您的
SolrInputDocument
中引用的这四个字段在schema.xml的
部分声明。请根据需要参考
另外,请注意,
CommonHttpSolrServer
已被弃用,取而代之的是,因此,我建议使用该类。您好,谢谢您的回复-但由于我是solr新手-我想我应该在该文件夹中添加字段-../example/solr/collection1/conf,或者我错了,我忘了感谢您-现在索引一切都好了