Radim Burget
Radim Burget

Reputation: 1516

Solrj Hello world - /solr/update Not Found

I followed the tutorial to use Solrj (and updated to most recent Solrj version 6.0.1),

1) Downloaded Solr

2) Started solr server from command line using

solr-6.0.1\bin>solr start

Seems everything OK, http://localhost:8983/solr/ can be viewed in a browser

3) Executed HelloWorld Solrj code:

public class SolrClientHelloWorld {

    public static void main(String args[]) {
        try {
            HttpSolrClient server = new HttpSolrClient (
                    "http://localhost:8983/solr/");
            SolrInputDocument doc = new SolrInputDocument();
            doc.addField("id", "tsetstst3r4", 1.0f);
            doc.addField("name", "doc1", 1.0f);
            doc.addField("price", 10);
            server.add(doc);        
        } catch(Exception e) {
            e.printStackTrace();
        }
    }
}

Exception

org.apache.solr.client.solrj.impl.HttpSolrClient$RemoteSolrException: Error from server at http://localhost:8983/solr: Expected mime type application/octet-stream but got text/html. Error 404 Not Found

HTTP ERROR 404

Problem accessing /solr/update. Reason:

    Not
Found

at org.apache.solr.client.solrj.impl.HttpSolrClient.executeMethod(HttpSolrClient.java:545) at org.apache.solr.client.solrj.impl.HttpSolrClient.request(HttpSolrClient.java:241) at org.apache.solr.client.solrj.impl.HttpSolrClient.request(HttpSolrClient.java:230) at org.apache.solr.client.solrj.SolrRequest.process(SolrRequest.java:149) at org.apache.solr.client.solrj.SolrClient.add(SolrClient.java:173) at org.apache.solr.client.solrj.SolrClient.add(SolrClient.java:138) at org.apache.solr.client.solrj.SolrClient.add(SolrClient.java:152) at SolrClient.main(SolrClient.java:16)

Environment: Windows 10, java version "1.8.0_91"

Did I miss something to configure on the Solr server?

Related answers that that seems gives no solution:

Upvotes: 1

Views: 2427

Answers (3)

Two things needs to be done before indexing.

1.You must have a core or collection to index the data in SOLR.
2.You must add the core/collection name in the SOLR base URL

Example

1. Start and create core/collection in SOLR

SOLR Standalone mode (core):

bin>solr start
bin>solr create_core -c test -p 8983 -d basic_configs

SOLR Cloud mode (collection):

bin>solr start -cloud
bin>solr create -c test -p 8983 -d basic_configs

Note : Kindly update your fields in schema.xml

2.SOLRJ

Update the above line from

HttpSolrClient server = new HttpSolrClient (
                    "http://localhost:8983/solr/");

To

HttpSolrClient server = new HttpSolrClient (
                    "http://localhost:8983/solr/test");

Note : Here my core/collection name is test

Upvotes: 3

MridulSri
MridulSri

Reputation: 81

For using Solr as a search engine you have to make a proper core with required field setting in schema.xml file.

you can also use the command for same

bin/solr create -help

bin/solr create [-c name] [-d confdir] [-n configName] [-shards #] [-replicationFactor #] [-p port]

by using above command you can create on core named with "test"

bin/solr create -c test

Then you can use the core by referring

HttpSolrClient server = new HttpSolrClient (
                "http://localhost:8983/solr/test");

Upvotes: 0

Radim Burget
Radim Burget

Reputation: 1516

There is needed to also create a core, for example with the name test:

solr create -c test

and access the url accordingly

HttpSolrClient server = new HttpSolrClient (
                    "http://localhost:8983/solr/test");

Upvotes: 0

Related Questions