Tania Marinova
Tania Marinova

Reputation: 1898

helloword solj programe goves me an exception 'bad request'

I try to index this data in solr from my java application.

The problem is that it gives me this exception

Exception in thread "main" org.apache.solr.common.SolrException: Bad Request

Bad Request

request: http://localhost:8983/solr/update?wt=javabin&version=2
    at org.apache.solr.client.solrj.impl.CommonsHttpSolrServer.request(CommonsHttpSolrServer.java:436)
    at org.apache.solr.client.solrj.impl.CommonsHttpSolrServer.request(CommonsHttpSolrServer.java:246)
    at org.apache.solr.client.solrj.request.AbstractUpdateRequest.process(AbstractUpdateRequest.java:104)
    at org.apache.solr.client.solrj.SolrServer.add(SolrServer.java:70)
    at org.apache.solr.client.solrj.SolrServer.add(SolrServer.java:55)
    at com.gismo.ReadFromSolr.main(ReadFromSolr.java:47)

Here is my code

public static void main(String[] args) throws SolrServerException, SQLException, IOException 
        { String url = "http://localhost:8983/solr/db";

     CommonsHttpSolrServer solrServer = new
                 CommonsHttpSolrServer("http://localhost:8983/solr");

                         SolrInputDocument doc1 = new SolrInputDocument();
                         doc1.addField( "pk_id", "id1");
                         doc1.addField("doc_type", "content");
                         doc1.addField( "id", "1");
                         doc1.addField( "content_text", "hello world" );

                         Collection<SolrInputDocument> docs = new
                         ArrayList<SolrInputDocument>();
                         docs.add(doc1);
                         solrServer.add(docs);
                         solrServer.commit(); 
    }

So I've got one more questions

1. Do i need to declarethis fields somewhere before indexing : for example in solr C:\solr-4.1.0\example\solr\collection1\conf\schema.xml

Upvotes: 0

Views: 557

Answers (1)

Paige Cook
Paige Cook

Reputation: 22555

Yes, you will need to make sure those four fields you are referencing in your SolrInputDocument are declared in the <fields> section of your schema.xml. Please reference SchemaXml as needed.

Also, please note that CommonsHttpSolrServer has been deprecated favor of HttpSolrServer, so I would recommend using that class.

Upvotes: 1

Related Questions