- I tried using HttpSolrServer, but had some problems and some news
groups mentioned that it is buggy and I should be using
CommonsHttpSolrServer. So, I am using CommonsHttpSolrServer. But both
approaches does not work.
- I have tried using SOLR 4.0 as well as 3.6.1. I get errors in both cases.
- I started SOLR server from C:\apche_solr\apache-solr-4.0.0\example
using the command "java -Dsolr.solr.home="./example-DIH/solr/" -jar
start.jar 1>logs/dih.log 2>&1"
Here is my code which uses CommonsHttpSolrServer:
String url = "http://localhost:8983/solr/#/solr/update/";
try {
CommonsHttpSolrServer server = new CommonsHttpSolrServer( url );
server.setSoTimeout(1000); // socket read timeout
server.setConnectionTimeout(100);
server.setDefaultMaxConnectionsPerHost(100);
server.setMaxTotalConnections(100);
server.setFollowRedirects(false); // defaults to false
server.setAllowCompression(false);
server.setMaxRetries(1); // defaults to 0. > 1 not recommended.
server.setParser(new XMLResponseParser()); // binary parser is used
by default
SolrInputDocument doc2 = new SolrInputDocument();
doc2.addField( "OR", "119.96");
doc2.addField( "M", "1");
doc2.addField( "PT", "94.5946");
doc2.addField( "PY" , "12");
doc2.addField( "LR" , "118");
doc2.addField( "PC", "FST 04/26/12");
doc2.addField( "SN" , "OTHER");
doc2.addField( "CE", "2012-05-04T04:00:00Z");
doc2.addField( "VC", "184");
doc2.addField( "VR", "24563");
doc2.addField( "PR", "4539673");
doc2.addField( "SE", "2012-04-30T04:00:00Z");
doc2.addField( "IE", "2012-05-08T04:00:00Z");
doc2.addField( "ZR", "4539673");
doc2.addField( "PNT", "94.61079");
doc2.addField( "GY", "17");
doc2.addField( "id", "111_1111111_1_11_2");
doc2.addField( "PAR", "359.88");
doc2.addField( "CTE", "2012-04-26T04:00:00Z");
doc2.addField( "LE", "PDS LOCATION");
doc2.addField( "DR", "691");
doc2.addField( "OY", "4");
doc2.addField( "SS", "10");
Collection<SolrInputDocument> docs = new ArrayList<SolrInputDocument>();
docs.add( doc2 );
UpdateResponse resp = server.add( docs );
System.out.println(resp.getResponse());
server.commit(true, true);
}
catch (Exception e) {
System.out.println(e);
e.printStackTrace();
}
When I run this code, I get the following exception:
org.apache.solr.common.SolrException: parsing error
org.apache.solr.common.SolrException: parsing error
at
org.apache.solr.client.solrj.impl.XMLResponseParser.processResponse(XMLResponseParser.java:143)
at
org.apache.solr.client.solrj.impl.XMLResponseParser.processResponse(XMLResponseParser.java:104)
at
org.apache.solr.client.solrj.impl.CommonsHttpSolrServer.request(CommonsHttpSolrServer.java:469)
at
org.apache.solr.client.solrj.impl.CommonsHttpSolrServer.request(CommonsHttpSolrServer.java:249)
at
org.apache.solr.client.solrj.request.AbstractUpdateRequest.process(AbstractUpdateRequest.java:105)
at org.apache.solr.client.solrj.SolrServer.add(SolrServer.java:69)
at org.apache.solr.client.solrj.SolrServer.add(SolrServer.java:54)
at SolrIndexClient.indexTest(SolrIndexClient.java:117)
at SolrIndexClient.main(SolrIndexClient.java:139)
Caused by: java.lang.Exception: really needs to be response or result.
not:html
at
org.apache.solr.client.solrj.impl.XMLResponseParser.processResponse(XMLResponseParser.java:134)
Any idea what is going on? I do not see anything in the log file. I am
not sure if my request is even hitting the server. In our
implementation, we need to update the indexes programatically in
near-real time. If we can't do this, then SOLR is unusable for us .
Thanks in advance,
Jegan Mehalingam