Warm tip: This article is reproduced from stackoverflow.com, please click
java solr solrj lotus-domino

Error Connecting to Solr using Solrj from Java

发布于 2020-05-02 23:01:16

On my local machine I have installed Solr v8.4.1 to do some testing and have created a core, added some data using json file and can connect to the Admin client on "http://127.0.0.1:8983/solr/".

I am now trying to connect to the instance via Solrj (Java) using a Lotus Domino agent.

 solrServer = new HttpSolrServer("http://127.0.0.1:8983/solr/");
        solrServer.setSoTimeout(10000);
        solrServer.setConnectionTimeout(10000);
        solrServer.setDefaultMaxConnectionsPerHost(100);
        solrServer.setMaxTotalConnections(100);
        solrServer.setFollowRedirects(false);
        solrServer.setAllowCompression(true);
        solrServer.setMaxRetries(1);
       // solrServer.setParser(new XMLResponseParser());

        System.out.println(solrServer.getBaseURL());

        SolrQuery query = new SolrQuery();
        query.setQuery( "*:*" );
        try {
          System.out.println("queryyyy");
            QueryResponse rsp = solrServer.query( query );

            Iterator<SolrDocument> iter = rsp.getResults().iterator();

            while (iter.hasNext()) {
              SolrDocument resultDoc = iter.next();

              String id = (String) resultDoc.getFieldValue("id"); //id is the uniqueKey field
              System.out.println(id);
             // if (rsp.getHighlighting().get(id) != null) {
              //  List<String> highlightSnippets = rsp.getHighlighting().get(id).get("content");
             // }
            }


        } catch (SolrServerException e1) {
            System.out.println("error here");
            e1.printStackTrace();
        }

However when I try and make a connection using the above code, I get the following error.

    org.apache.solr.client.solrj.SolrServerException: IOException occured when talking to server at: http://127.0.0.1:8983/solr/
    at org.apache.solr.client.solrj.impl.HttpSolrServer.executeMethod(HttpSolrServer.java:562)
    at org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:210)
    at org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:206)
    at org.apache.solr.client.solrj.request.QueryRequest.process(QueryRequest.java:91)
    at org.apache.solr.client.solrj.SolrServer.query(SolrServer.java:301)
    at JavaAgent.init(Unknown Source)
    at JavaAgent.NotesMain(Unknown Source)
    at lotus.domino.AgentBase.runNotes(Unknown Source)
    at lotus.domino.NotesThread.run(Unknown Source)
Caused by: java.net.UnknownHostException:  :  
    at java.net.InetAddress.getAllByName0(InetAddress.java:1413)
    at java.net.InetAddress.getAllByName(InetAddress.java:1322)
    at java.net.InetAddress.getAllByName(InetAddress.java:1245)
    at org.apache.http.impl.conn.SystemDefaultDnsResolver.resolve(SystemDefaultDnsResolver.java:44)
    at org.apache.http.impl.conn.DefaultClientConnectionOperator.resolveHostname(DefaultClientConnectionOperator.java:260)
    at org.apache.http.impl.conn.DefaultClientConnectionOperator.openConnection(DefaultClientConnectionOperator.java:160)
    at org.apache.http.impl.conn.ManagedClientConnectionImpl.open(ManagedClientConnectionImpl.java:304)
    at org.apache.http.impl.client.DefaultRequestDirector.tryConnect(DefaultRequestDirector.java:610)
    at org.apache.http.impl.client.DefaultRequestDirector.execute(DefaultRequestDirector.java:445)
    at org.apache.http.impl.client.AbstractHttpClient.doExecute(AbstractHttpClient.java:863)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:82)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:106)
    at org.apache.http.impl.client.CloseableHttpClient.execute(CloseableHttpClient.java:57)
    at org.apache.solr.client.solrj.impl.HttpSolrServer.executeMethod(HttpSolrServer.java:448)

It appears that it is having trouble connecting to the instance via this URL.

Any ideas would be greatly appreciated.

Questioner
Thinkpad
Viewed
64
Thinkpad 2020-02-21 20:26

I managed to work out what my problem was.

I was trying to connect to a version of Solr v8.4.1 but was using the SolrJ jar from version 4. When I updated my SolrJ jar to v8.4.1 it started to work.

Thanks for the replies.