使用Solr進行添加時報錯的解決方式

DEBUG [main] - Creating new http client, config:maxConnections=128&maxConnectionsPerHost=32&followRedirects=false
DEBUG [main] - Connection request: [route: {}->http://localhost:8055][total kept alive: 0; route allocated: 0 of 32; total allocated: 0 of 128]
DEBUG [main] - Connection leased: [id: 0][route: {}->http://localhost:8055][total kept alive: 0; route allocated: 1 of 32; total allocated: 1 of 128]
DEBUG [main] - Connecting to localhost:8055
DEBUG [main] - CookieSpec selected: best-match
DEBUG [main] - Auth cache not set in the context
DEBUG [main] - Target auth state: UNCHALLENGED
DEBUG [main] - Proxy auth state: UNCHALLENGED
DEBUG [main] - Attempt 1 to execute request
DEBUG [main] - Sending request: POST /solr_home/article/update?wt=javabin&version=2 HTTP/1.1
DEBUG [main] -  >> "POST /solr_home/article/update?wt=javabin&version=2 HTTP/1.1[\r][\n]"
DEBUG [main] -  >> "User-Agent: Solr[org.apache.solr.client.solrj.impl.HttpSolrServer] 1.0[\r][\n]"
DEBUG [main] -  >> "Transfer-Encoding: chunked[\r][\n]"
DEBUG [main] -  >> "Content-Type: application/xml; charset=UTF-8[\r][\n]"
DEBUG [main] -  >> "Host: localhost:8055[\r][\n]"
DEBUG [main] -  >> "Connection: Keep-Alive[\r][\n]"
DEBUG [main] -  >> "[\r][\n]"
DEBUG [main] - >> POST /solr_home/article/update?wt=javabin&version=2 HTTP/1.1
DEBUG [main] - >> User-Agent: Solr[org.apache.solr.client.solrj.impl.HttpSolrServer] 1.0
DEBUG [main] - >> Transfer-Encoding: chunked
DEBUG [main] - >> Content-Type: application/xml; charset=UTF-8
DEBUG [main] - >> Host: localhost:8055
DEBUG [main] - >> Connection: Keep-Alive
DEBUG [main] -  >> "7e[\r][\n]"
DEBUG [main] -  >> "<add><doc boost="1.0"><field name="id">1</field><field name="name">[0xe8][0x8b][0xb9][0xe6][0x9e][0x9c]7</field><field name="price">5000</field></doc></add>"
DEBUG [main] -  >> "[\r][\n]"
DEBUG [main] -  >> "0[\r][\n]"
DEBUG [main] -  >> "[\r][\n]"
DEBUG [main] -  << "HTTP/1.1 404 Not Found[\r][\n]"
DEBUG [main] -  << "Server: Apache-Coyote/1.1[\r][\n]"
DEBUG [main] -  << "Content-Type: text/html;charset=utf-8[\r][\n]"
DEBUG [main] -  << "Content-Language: en[\r][\n]"
DEBUG [main] -  << "Content-Length: 999[\r][\n]"
DEBUG [main] -  << "Date: Wed, 30 Nov 2016 16:54:03 GMT[\r][\n]"
DEBUG [main] -  << "[\r][\n]"
DEBUG [main] - Receiving response: HTTP/1.1 404 Not Found
DEBUG [main] - << HTTP/1.1 404 Not Found
DEBUG [main] - << Server: Apache-Coyote/1.1
DEBUG [main] - << Content-Type: text/html;charset=utf-8
DEBUG [main] - << Content-Language: en
DEBUG [main] - << Content-Length: 999
DEBUG [main] - << Date: Wed, 30 Nov 2016 16:54:03 GMT
DEBUG [main] - Connection can be kept alive indefinitely
DEBUG [main] -  << "<html><head><title>Apache Tomcat/7.0.52 - Error report</title><style><!--H1 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:22px;} H2 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:16px;} H3 {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;font-size:14px;} BODY {font-family:Tahoma,Arial,sans-serif;color:black;background-color:white;} B {font-family:Tahoma,Arial,sans-serif;color:white;background-color:#525D76;} P {font-family:Tahoma,Arial,sans-serif;background:white;color:black;font-size:12px;}A {color : black;}A.name {color : black;}HR {color : #525D76;}--></style> </head><body><h1>HTTP Status 404 - /solr_home/article/update</h1><HR size="1" noshade="noshade"><p><b>type</b> Status report</p><p><b>message</b> <u>/solr_home/article/update</u></p><p><b>description</b> <u>The requested resource is not available.</u></p><HR size="1" noshade="noshade"><h3>Apache Tomcat/7.0.52</h3></body></html>"
DEBUG [main] - Connection [id: 0][route: {}->http://localhost:8055] can be kept alive indefinitely
DEBUG [main] - Connection released: [id: 0][route: {}->http://localhost:8055][total kept alive: 1; route allocated: 1 of 32; total allocated: 1 of 128]

 

 以下爲執行的代碼:

/**
* @throws IOException 
* @throws SolrServerException 
* 更新:如果id存在,就執行這個更新操作,否則執行添加操作
* @Title: testCreateOrUpdateIndex
* @Description: 
* @return void
* @throws
*/

  @Test

  public void  testCreateOrUpdateIndex() throws SolrServerException, IOException{


//1.連接數據庫
String baseUrl="http://localhost:8055/solr/article";
HttpSolrServer httpSolrServer=new HttpSolrServer(baseUrl);

//建立SolrInputDocument對象
SolrInputDocument solrInputDocument=new SolrInputDocument();
solrInputDocument.addField("id", 1);
solrInputDocument.addField("name","蘋果7");
solrInputDocument.addField("price","5000");
   
//建立索引
httpSolrServer.add(solrInputDocument);
//提交
httpSolrServer.commit();
}



解決方式如下:

1.字段名稱和solr服務器中存儲的字段名稱不對應!

2.如例子中的http://localhost:8055/solr/article是否能正常在地址欄打開,注意:這個url中不能出現井號!

3.如還出現以上問題,建議仔細查看日誌說明或者控制檯錯誤提示,這個步驟推薦最先執行。






發表評論
所有評論
還沒有人評論,想成為第一個評論的人麼? 請在上方評論欄輸入並且點擊發布.
相關文章