开发者社区> 问答> 正文

使用solrj遇到奇怪问题?报错

@RequestMapping(value = "/solr", method = RequestMethod.GET)
	public void getSolr() throws SolrServerException, IOException {

		String urlString = "http://192.168.10.129:8983/solr/mycore";
		SolrClient client = new HttpSolrClient.Builder(urlString).build();
		SolrInputDocument doc = new SolrInputDocument();
		doc.addField("id", "c");
		client.add(doc);
		client.commit();
	}

就是创建个索引,然后就报错啦

Caused by: org.apache.solr.client.solrj.SolrServerException: IOException occured when talking to server at: http://192.168.10.129:8983/solr/mycore
	at org.apache.solr.client.solrj.impl.HttpSolrClient.executeMethod(HttpSolrClient.java:624)
	at org.apache.solr.client.solrj.impl.HttpSolrClient.request(HttpSolrClient.java:279)
	at org.apache.solr.client.solrj.impl.HttpSolrClient.request(HttpSolrClient.java:268)
	at org.apache.solr.client.solrj.SolrRequest.process(SolrRequest.java:160)
	at org.apache.solr.client.solrj.SolrClient.commit(SolrClient.java:484)
	at org.apache.solr.client.solrj.SolrClient.commit(SolrClient.java:463)
	at com.ansel.testall.solrController.getSolr(solrController.java:23)
	at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)
	at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:62)
	at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
	at java.lang.reflect.Method.invoke(Method.java:498)
	at org.springframework.web.method.support.InvocableHandlerMethod.doInvoke(InvocableHandlerMethod.java:221)
	at org.springframework.web.method.support.InvocableHandlerMethod.invokeForRequest(InvocableHandlerMethod.java:136)
	at org.springframework.web.servlet.mvc.method.annotation.ServletInvocableHandlerMethod.invokeAndHandle(ServletInvocableHandlerMethod.java:114)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.invokeHandlerMethod(RequestMappingHandlerAdapter.java:827)
	at org.springframework.web.servlet.mvc.method.annotation.RequestMappingHandlerAdapter.handleInternal(RequestMappingHandlerAdapter.java:738)
	at org.springframework.web.servlet.mvc.method.AbstractHandlerMethodAdapter.handle(AbstractHandlerMethodAdapter.java:85)
	at org.springframework.web.servlet.DispatcherServlet.doDispatch(DispatcherServlet.java:963)
	at org.springframework.web.servlet.DispatcherServlet.doService(DispatcherServlet.java:897)
	at org.springframework.web.servlet.FrameworkServlet.processRequest(FrameworkServlet.java:970)
	... 52 common frames omitted
Caused by: org.apache.http.NoHttpResponseException: 192.168.10.129:8983 failed to respond
	at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:141)
	at org.apache.http.impl.conn.DefaultHttpResponseParser.parseHead(DefaultHttpResponseParser.java:56)
	at org.apache.http.impl.io.AbstractMessageParser.parse(AbstractMessageParser.java:259)
	at org.apache.http.impl.AbstractHttpClientConnection.receiveResponseHeader(AbstractHttpClientConnection.java:281)
	at org.apache.http.impl.conn.DefaultClientConnection.receiveResponseHeader(DefaultClientConnection.java:257)
	at org.apache.http.impl.conn.ManagedClientConnectionImpl.receiveResponseHeader(ManagedClientConnectionImpl.java:207)
	at org.apache.http.protocol.HttpRequestExecutor.doReceiveResponse(HttpRequestExecutor.java:273)
	at org.apache.http.protocol.HttpRequestExecutor.execute(HttpRequestExecutor.java:125)
	at org.apache.http.impl.client.DefaultRequestDirector.tryExecute(DefaultRequestDirector.java:684)
	at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:486)
	at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:835)
	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:83)
	at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:56)
	at org.apache.solr.client.solrj.impl.HttpSolrClient.executeMethod(HttpSolrClient.java:515)
	... 71 common frames omitted

doc是被add进去了,但是commit失败了。

如果把add doc和commit分成2次请求就没问题了,如下:

@RequestMapping(value = "/solr", method = RequestMethod.GET)
	public void getSolr() throws SolrServerException, IOException {

		String urlString = "http://192.168.10.129:8983/solr/mycore";
		SolrClient client = new HttpSolrClient.Builder(urlString).build();
		SolrInputDocument doc = new SolrInputDocument();
		doc.addField("id", "c");
		client.add(doc);
	}
	@RequestMapping(value = "/solr2", method = RequestMethod.GET)
	public void getSolr2() throws SolrServerException, IOException {

		String urlString = "http://192.168.10.129:8983/solr/mycore";
		SolrClient client = new HttpSolrClient.Builder(urlString).build();
		client.commit();
	}

执行query操作也没有问题。

solr:6.60

jdk:1.8

iteye上一个类似的情况:

http://www.iteye.com/problems/101190

展开
收起
爱吃鱼的程序员 2020-06-08 13:38:16 486 0
1 条回答
写回答
取消 提交回答
  • https://developer.aliyun.com/profile/5yerqm5bn5yqg?spm=a2c6h.12873639.0.0.6eae304abcjaIB

    很深奥的样子

    临时解决方案,使用如下方法提交:

    UpdateRequestreq=newUpdateRequest();req.setAction(UpdateRequest.ACTION.COMMIT,false,false);req.add(doc);UpdateResponsersp=req.process(client);

    https://wiki.apache.org/solr/...上找到的,
    这个是部分译文 http://www.cnblogs.com/llz502...

    为什么这样就可以了呢?还是好奇怪

    2020-06-08 13:38:33
    赞同 展开评论 打赏
问答分类:
问答地址:
问答排行榜
最热
最新

相关电子书

更多
Apache NiFi Crash Course Intro 立即下载
低代码开发师(初级)实战教程 立即下载
阿里巴巴DevOps 最佳实践手册 立即下载