2013-01-07 38 views
1

我有一個solr實例正在運行,並且能夠通過瀏覽器訪問它並使用Admin運行查詢。當我嘗試通過在Eclipse Java代碼來訪問它,但是,我收到以下錯誤:從Eclipse訪問Solr時出現404錯誤

Exception in thread "main" org.apache.solr.common.SolrException: Server at http://localhost:8983/solr returned non ok status:404, message:Not Found 
at org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:372) 
at org.apache.solr.client.solrj.impl.HttpSolrServer.request(HttpSolrServer.java:181) 
at org.apache.solr.client.solrj.request.QueryRequest.process(QueryRequest.java:90) 
at org.apache.solr.client.solrj.SolrServer.query(SolrServer.java:301) 
at testClass.main(testClass.java:18) 

這裏是我運行代碼:

public static void main(String[] args) throws MalformedURLException, SolrServerException { 
    SolrServer server = new HttpSolrServer("http://localhost:8983/solr/"); 
    ModifiableSolrParams params = new ModifiableSolrParams(); 
    params.set("myParam", "myValue"); 
    QueryResponse response = server.query(params); 
} 

回答

1

事實證明,我有兩個錯誤:

1)我的設置實際上有一個嵌套的Solr目錄所以我需要再添加一個「Solr的」水平。

2)我正在設置params變量不正確。發送的第一個參數應該是「q」,第二個參數是「name:value」對。

更新例子,包括一次傳遞多個PARAMS:

public static void main(String[] args) throws MalformedURLException, SolrServerException { 
    SolrServer server = new HttpSolrServer("http://localhost:8983/solr/solr/"); 
    ModifiableSolrParams params = new ModifiableSolrParams(); 
    params.set("q", "param1:value1 AND param2:value2"); 
    QueryResponse response = server.query(params); 
    System.out.println("response = " + response); 
} 
0

它不應該是: -

SolrServer server = new HttpSolrServer("http://localhost:8983/solr"); 

請參閱以下鏈接接受的答案: -

Querying Solr via Solrj: Basics

+0

我在這兩種情況下得到同樣的錯誤 – vincentvanjoe