2017-07-10 4 views
0

Solr 5.5.4とJavaをSolrJ jarで接続しようとしましたが、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> 

Getingエラー:

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 " - このURLはsolrの管理UIを示していますが、このシナリオで"# "urlを使って正しい方法を得ることができます。 –

+0

上記のスクリーンショットには "localhost:8983/solr /#/ gettingstarted"という出力が表示されます。 –

+1

あなたの質問は、なぜ '#'(アンカータグまたはハッシュタグ)が私たちのケースで大きな違いを生むのか、URLがどのようにビルドされ、誰がそのURLを読むかによって異なります。リーダーがサーバー(Solrなど)、Webアプリケーション、またはブラウザーの場合厳密には、Solr Admin UIとSolrとSolrJの間で違いがあります。 https://en.wikipedia.org/wiki/URL(構文と断片部分)を読むことを強くお勧めします – freedev

関連する問題