Solr 4 with basic authentication

前端 未结 3 1233
野趣味
野趣味 2021-01-20 08:27

I am trying to connect to solr using solrj. My solr instance runs in jetty and is protected with basic authentication. I found these links that contain relevant information.

3条回答
  •  不思量自难忘°
    2021-01-20 08:52

    According to the Solr Security - SolrJ section on Solr Wiki you should be able to do the following:

     public static void main(String[] args) throws SolrServerException, IOException {
    
         HttpSolrServer server = new HttpSolrServer("http://localhost:8983/solr/");
    
         HttpClientUtil.setBasicAuth(server.getHttpClient(), USERNAME, PASSWORD);
    
         SolrInputDocument document = new SolrInputDocument();
         document.addField("id",123213);
         server.add(document);
         server.commit();
    
     }
    

提交回复
热议问题