i am trying to index documents with solrj, this is my code,
import org.apache.solr.client.solrj.SolrServerException;
import org.apache.solr.client.solrj.impl.*;
import org.apache.solr.common.SolrInputDocument;
import java.io.IOException;
public class index {
public static void main(String[] args) throws IOException, SolrServerException {
String url = "http://localhost:8080/solr/document/";
HttpSolrServer server = new HttpSolrServer( url );
server.setMaxRetries(1); // defaults to 0. > 1 not recommended.
server.setConnectionTimeout(5000);
server.setSoTimeout(1000); // socket read timeout
server.setDefaultMaxConnectionsPerHost(100);
server.setMaxTotalConnections(100);
server.setFollowRedirects(false); // defaults to false
SolrInputDocument doc1 = new SolrInputDocument();
doc1.addField( "id", 23);
doc1.addField( "title", "doc1" );
doc1.addField( "author","Chetan Bhagat" );
doc1.addField( "contents", "I am the best." );
doc1.addField( "date_modified", "12-12-2014" );
server.commit();
}
}
After running the console on eclipse shows this:
Dec 21, 2013 2:07:25 AM org.apache.solr.client.solrj.impl.HttpClientUtil createClient INFO: Creating new http client, config:maxConnections=128&maxConnectionsPerHost=32&followRedirects=false
What causes this abnormal termination?? I am new to solr.
You seem to be missing adding the the "document" to the "server":
...
SolrInputDocument doc1 = new SolrInputDocument();
doc1.addField( "id", 23);
doc1.addField( "title", "doc1" );
doc1.addField( "author","Chetan Bhagat" );
doc1.addField( "contents", "I am the best." );
doc1.addField( "date_modified", "12-12-2014" );
server.add(doc1); // **MISSING LINE!!**
server.commit();
...
This is probably the reason why you are not seeing the document in the Solr index. This is an example of "adding document" to Solr: http://www.solrtutorial.com/solrj-tutorial.html
HTH.