gpt4 book ai didi

java - hello world solj 程序给了我一个异常 'bad request'

转载 作者:行者123 更新时间:2023-12-01 14:43:28 25 4
gpt4 key购买 nike

我尝试从我的 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

最佳答案

是的,您需要确保您在 SolrInputDocument 中引用的这四个字段在 <fields> 中声明schema.xml 的部分。请引用SchemaXml如所须。

另外,请注意 CommonsHttpSolrServer已弃用 HttpSolrServer ,所以我建议使用该类。

关于java - hello world solj 程序给了我一个异常 'bad request',我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/15707462/

25 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com