我尝试从我的 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.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();
}
所以我还有一个问题
1. 我是否需要在索引之前在某处声明此字段:例如在 solr C:\solr-4.1.0\example\solr\collection1\conf\schema.xml