我正在尝试更新solr中的文档。逻辑所在的方法是用两个不同的tomcats编写的,即Tomcat v6.0
和Tomcat v8.0
,但基本上是相同的代码。后来的版本工作正常,但前者不是。
v4.0x
v6.0
包含apache-solr-solrj-3.6.0
jar v8.0
包含solr-solrj-4.10.3
jar。以下是我处理Tomcat v6
org.apache.solr.client.solrj.SolrServerException:http://10.210.16.66:8084/solr/mydoc处的服务器返回非正常状态:400,消息:错误请求 在org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:328) 在org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:211) 在org.apache.solr.client.solrj.request.AbstractUpdateRequest.process(AbstractUpdateRequest.java:105) 在org.apache.solr.client.solrj.SolrServer.add(SolrServer.java:121) at mypackage.solr.SolrPortal.addUpdateRecordsToSolr(SolrPortal.java:171) 在mypackage.updateFAQSolr(PortalDocumentsDAO.java:1761) at mypackage.saveFaqlogs(PortalDocumentsDAO.java:1230) 在org.apache.jsp.jsp.saveFaqlog_jsp._jspService(saveFaqlog_jsp.java:72) 在org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70) 在javax.servlet.http.HttpServlet.service(HttpServlet.java:723) 在org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:388) 在org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:313) 在org.apache.jasper.servlet.JspServlet.service(JspServlet.java:260) 在javax.servlet.http.HttpServlet.service(HttpServlet.java:723) 在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:290) 在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) at mypackage.servlet.SessionFilterAll.doFilter(SessionFilterAll.java:79) 在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) 在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 在com.myecw.servlet.JspFilter.doFilter(JspFilter.java:33) 在org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:235) 在org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:206) 在org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:233) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:191) 在org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:470) 在org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:127) 在org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103) 在org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) 在org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:293) 在org.apache.coyote.http11.Http11AprProcessor.process(Http11AprProcessor.java:879) 在org.apache.coyote.http11.Http11AprProtocol $ Http11ConnectionHandler.process(Http11AprProtocol.java:617) 在org.apache.tomcat.util.net.AprEndpoint $ Worker.run(AprEndpoint.java:1760) 在java.lang.Thread.run(Thread.java:619)
以下是solr
org.apache.solr.common.SolrException:不支持的ContentType:application / octet-stream不在:[application / xml,text / csv,text / json,application / csv,application / javabin, text / xml,application / json]
代码:
public void updateFAQSolr(){
StringBuilder str = new StringBuilder();
str.append(" My query to update data ");
System.out.println(" NEW solr query is -> " + str.toString());
SolrPortal se = new SolrPortal("faqdata");
se.addUpdateRecordsToSolr(str.toString());
}
public void addUpdateRecordsToSolr(String query) {
RootSlave rootslave = null;
Connection con = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
ResultSetMetaData rsmd = null;
try {
rootslave = new RootSlave();
rootslave.initconnection();
con = rootslave.con;
pstmt = con.prepareStatement(query);
rs = pstmt.executeQuery();
rsmd = rs.getMetaData();
int colCount = rsmd.getColumnCount();
while(rs.next()) {
SolrInputDocument doc = new SolrInputDocument();
for(int i=1;i<colCount;i++) {
String label = rsmd.getColumnLabel(i);
doc.addField(label, rs.getObject(i));
}
System.out.println("content type is ->> "+getContentType());
solrServer.add(doc,10000);
}
solrServer.commit();
}catch(Exception e) {
e.printStackTrace();
EmgrLog.AppendExceptionToLog(e);
}finally {
RootSlave.close(rs);
RootSlave.close(pstmt);
RootSlave.close(con);
}
}
PS:内容类型明确设置为application\json
编辑:
Tomcat 6.0 Document
使用solr-solrj-4.10.3
输出
SolrInputDocument[{views=views(1.0)={1585}}}]
Tomcat 8.0 Document
使用apache-solr-solrj-3.6.0
输出
SolrInputDocument(fields: [views=1585])