2017-07-10 29 views
0

我試圖用SolrJ jar來連接Solr 5.5.4,但是Solr沒有連接。它會得到一些錯誤。SolrJ - RemoteSolrException引發連接到Solr 5.5.4

try{ 
    String urlString = "http://localhost:8983/solr/#/gettingstarted"; 
    HttpSolrClient solrClient = new HttpSolrClient(urlString); 
    QueryResponse queryResponse = solrClient.query(new SolrQuery("*:*")); 
    System.out.println(queryResponse.toString()); 
} catch (SolrServerException e) { 
    e.printStackTrace(); 
} catch (IOException e) { 
    e.printStackTrace(); 
} catch (Exception e) { 
    e.printStackTrace(); 
} 

這是Maven的依賴性:

<dependency> 
    <groupId>org.apache.solr</groupId> 
    <artifactId>solr-solrj</artifactId> 
    <version>5.5.4</version> 
</dependency> 

葛亭錯誤:

org.apache.solr.client.solrj.impl.HttpSolrClient$RemoteSolrException: Error from server at http://localhost:8983/solr/#/gettingstarted: Expected mime type application/octet-stream but got text/html. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd"> 
<html> 

<!-- 
Licensed to the Apache Software Foundation (ASF) under one or more 
contributor license agreements. See the NOTICE file distributed with 
this work for additional information regarding copyright ownership. 
The ASF licenses this file to You under the Apache License, Version 2.0 
(the "License"); you may not use this file except in compliance with 
the License. You may obtain a copy of the License at 

http://www.apache.org/licenses/LICENSE-2.0 

Unless required by applicable law or agreed to in writing, software 
distributed under the License is distributed on an "AS IS" BASIS, 
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied. 
See the License for the specific language governing permissions and 
limitations under the License. 
--> 

<head> 

    <title>Solr Admin</title> 

    <link rel="icon" type="image/x-icon" href="img/favicon.ico?_=5.5.4"> 
    <link rel="shortcut icon" type="image/x-icon" href="img/favicon.ico?_=5.5.4"> 

    <link rel="stylesheet" type="text/css" href="css/styles/common.css?_=5.5.4"> 
    <link rel="stylesheet" type="text/css" href="css/styles/analysis.css?_=5.5.4"> 
    <link rel="stylesheet" type="text/css" href="css/styles/cloud.css?_=5.5.4"> 
    <link rel="stylesheet" type="text/css" href="css/styles/cores.css?_=5.5.4"> 
    <link rel="stylesheet" type="text/css" href="css/styles/dashboard.css?_=5.5.4"> 
    <link rel="stylesheet" type="text/css" href="css/styles/dataimport.css?_=5.5.4"> 
    <link rel="stylesheet" type="text/css" href="css/styles/files.css?_=5.5.4"> 
    <link rel="stylesheet" type="text/css" href="css/styles/index.css?_=5.5.4"> 
    <link rel="stylesheet" type="text/css" href="css/styles/java-properties.css?_=5.5.4"> 
    <link rel="stylesheet" type="text/css" href="css/styles/logging.css?_=5.5.4"> 
    <link rel="stylesheet" type="text/css" href="css/styles/menu.css?_=5.5.4"> 
    <link rel="stylesheet" type="text/css" href="css/styles/plugins.css?_=5.5.4"> 
    <link rel="stylesheet" type="text/css" href="css/styles/documents.css?_=5.5.4"> 
    <link rel="stylesheet" type="text/css" href="css/styles/query.css?_=5.5.4"> 
    <link rel="stylesheet" type="text/css" href="css/styles/replication.css?_=5.5.4"> 
    <link rel="stylesheet" type="text/css" href="css/styles/schema-browser.css?_=5.5.4"> 
    <link rel="stylesheet" type="text/css" href="css/styles/threads.css?_=5.5.4"> 
    <link rel="stylesheet" type="text/css" href="css/styles/segments.css?_=5.5.4"> 
    <link rel="stylesheet" type="text/css" href="css/chosen.css?_=5.5.4"> 

    <meta http-equiv="x-ua-compatible" content="IE=9"> 

    <script type="text/javascript"> 

    var app_config = {}; 

    app_config.solr_path = '\/solr'; 
    app_config.core_admin_path = '\/admin\/cores'; 

    </script> 

</head> 
<body> 

    <div id="wrapper"> 

    <div id="header"> 

     <a href="./" id="solr"><span>Apache SOLR</span></a> 

     <p id="environment">&nbsp;</p> 

    </div> 

    <div id="main" class="clearfix"> 

     <div id="init-failures"> 

      <h2>SolrCore Initialization Failures</h2> 
      <ul></ul> 
      <p>Please check your logs for more information</p> 

     </div> 

     <div class="other-ui-link"> 
     Try <a class="ul" href="/solr/index.html">New UI</a><a target="_blank" href="http://wiki.apache.org/solr/AngularUI">&nbsp;<span class="help"></span></a> 
     </div> 

     <div id="content-wrapper"> 
     <div id="content"> 

      &nbsp; 

     </div> 
     </div> 

     <div id="menu-wrapper"> 
     <div> 

      <ul id="menu"> 

      <li id="index" class="global"><p><a href="#/">Dashboard</a></p></li> 

      <li id="logging" class="global"><p><a href="#/~logging">Logging</a></p> 
       <ul> 
       <li class="level"><a href="#/~logging/level">Level</a></li> 
       </ul> 
      </li> 

      <li id="cloud" class="global optional"><p><a href="#/~cloud">Cloud</a></p> 
       <ul> 
       <li class="tree"><a href="#/~cloud?view=tree">Tree</a></li> 
       <li class="graph"><a href="#/~cloud">Graph</a></li> 
       <li class="rgraph"><a href="#/~cloud?view=rgraph">Graph (Radial)</a></li> 
       <li class="dump"><a href="#/~cloud">Dump</a></li> 
       </ul> 
      </li> 

      <li id="cores" class="global"><p><a href="#/~cores">Core Admin</a></p></li> 

      <li id="java-properties" class="global"><p><a href="#/~java-properties">Java Properties</a></li> 

      <li id="threads" class="global"><p><a href="#/~threads">Thread Dump</a></p></li> 

      </ul> 

      <div id="core-selector"> 
      <div id="has-cores"> 
       <select data-placeholder="Core Selector"></select> 
      </div> 
      <p id="has-no-cores"><a href="#/~cores"> 
       No cores available 
       <span>Go and create one</span> 
      </a></p> 
      </div> 
      <div id="core-menu"> 
      <ul></ul> 
      </div> 

     </div> 
     </div> 

     <div id="meta"> 

     <ul> 

      <li class="documentation"><a href="http://lucene.apache.org/solr/"><span>Documentation</span></a></li> 
      <li class="issues"><a href="http://issues.apache.org/jira/browse/SOLR"><span>Issue Tracker</span></a></li> 
      <li class="irc"><a href="https://wiki.apache.org/solr/IRCChannels"><span>IRC Channel</span></a></li> 
      <li class="mailinglist"><a href="http://lucene.apache.org/solr/resources.html#community"><span>Community forum</span></a></li> 
      <li class="wiki-query-syntax"><a href="https://cwiki.apache.org/confluence/display/solr/Query+Syntax+and+Parsing"><span>Solr Query Syntax</span></a></li> 

     </ul> 

     </div> 

    </div> 

    </div> 

    <div id="connection_status"> 

    <span>Connection lost &hellip;</span> 

    </div> 

    <script type="text/javascript"> var require = { urlArgs: '_=5.5.4' }; </script> 
    <script src="js/require.js?_=5.5.4" data-main="js/main"></script> 

</body> 
</html> 

    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.query(SolrClient.java:942) 
    at org.apache.solr.client.solrj.SolrClient.query(SolrClient.java:957) 
    at com.test.solr.SOLRTEST.App.main(App.java:38) 

保證我Solr的運行截圖我附在下面, enter image description here

好心幫我,感謝提前。

+0

我搜索並找到很多鏈接,但這些對我沒有幫助。 –

回答

2

嘗試指定沒有錨#的Url,這應該是正確的方法。

String urlString = "http://localhost:8983/solr/gettingstarted"; 
HttpSolrClient solrClient = new HttpSolrClient(urlString); 

我認爲gettingstarted是您正在使用的集合名稱。

+0

謝謝mr.freedev,非常感謝你,先生,這個解決方案工作正常。但是,我有一些懷疑先生,「http:// localhost:8983/solr/gettingstarted」 - 當我使用這個URL瀏覽器顯示404(未找到)錯誤,「http:// localhost:8983/solr /#/ gettingstarted 「 - 這個網址顯示solr管理員界面,我怎麼才能在這種情況下得到正確的出」#「網址。 –

+0

你可以看到「localhost:8983/solr /#/ gettingstarted」輸出爲上面的附加屏幕截圖。 –

+1

你的問題,爲什麼'#'(定位標記或散列標記)在我們的情況下有很大的不同,取決於如何構建URL以及誰讀取該URL。如果閱讀器是服務器(例如Solr),Web應用程序或瀏覽器。嚴格地說,在我們的案例中,區別在於Solr管理界面和Solr與SolrJ之間的區別。我強烈建議閱讀https://en.wikipedia.org/wiki/URL(語法和片段部分) – freedev