使用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.如还出现以上问题,建议仔细查看日志说明或者控制台错误提示,这个步骤推荐最先执行。






评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值