SolrJ - RemoteSolrException 引发连接到 Solr 5.5.4

SolrJ - RemoteSolrException raised connecting to Solr 5.5.4

我尝试使用 java 将 Solr 5.5.4 与 SolrJ jar 连接,但 Solr 未连接。它有一些错误。

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 运行 我在下面附上的屏幕截图,

请帮助我,感谢提前。

尝试指定没有锚 # 的 Url,这应该是正确的方法。

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

我假设 gettingstarted 是您正在使用的集合的名称。