Apache Solr: Cannot add bean document with solrj

132 Views Asked by At

I installed a fresh new Apache Solr with Docker.

Here my docker-compose.yml

version: '3'
services:
  solr:
    image: solr:9.3.0
    ports:
     - "8983:8983"
    volumes:
      - ./data:/var/solr
    command:
      - solr-precreate
      - gettingstarted
volumes:
  data:

In my java code I have the following lines

final String solrUrl = "http://localhost:8983/solr/gettingstarted";
var client = new HttpSolrClient.Builder(solrUrl)
        .withConnectionTimeout(10000)
        .withSocketTimeout(60000)
        .build();

var doc = new TestDocument();
doc.setId(new Random().nextInt(Integer.MAX_VALUE-1));
doc.setContent("my first line of content");
doc.setCreateAt(LocalDateTime.now());


client.addBean(TestDocument.class.getName(), doc);
client.commit(TestDocument.class.getName());

I get an error add the addBean method.

Exception in thread "main" org.apache.solr.client.solrj.impl.BaseHttpSolrClient$RemoteSolrException: Error from server at http://localhost:8983/solr/gettingstarted: Expected mime type in [application/octet-stream, application/vnd.apache.solr.javabin] but got text/html. <p>
  Searching for Solr?<br/>
  You must type the correct path.<br/>
  Solr will respond.
</p>

    at org.apache.solr.client.solrj.impl.HttpSolrClient.executeMethod(HttpSolrClient.java:687)
    at org.apache.solr.client.solrj.impl.HttpSolrClient.request(HttpSolrClient.java:263)
    at org.apache.solr.client.solrj.impl.HttpSolrClient.request(HttpSolrClient.java:244)
    at org.apache.solr.client.solrj.SolrRequest.process(SolrRequest.java:234)
    at org.apache.solr.client.solrj.SolrClient.add(SolrClient.java:165)
    at org.apache.solr.client.solrj.SolrClient.addBean(SolrClient.java:262)
    at org.apache.solr.client.solrj.SolrClient.addBean(SolrClient.java:230)
    at Application.main(Application.java:31)

Do I need an other URL or I have to configure Solr at some point ?

0

There are 0 best solutions below