Search code examples
javasolrlucenesolrj

HTTP ERROR 404 while accessing solr admin


I am using solr-6.5.1. I was able to install Solr, create a collection, index files using my application and also search for data from Solr. I was using the following URL to access Solr: http://localhost:8983/solr/swcm Everything was working fine for me until today. Now when I try to access the above URL, it gives the following error:

HTTP ERROR 404

Problem accessing /solr/swcm. Reason:

    Not Found

But if I use the following URL: http://localhost:8983/solr/#/swcm I am able to access the Solr admin. But the issue with this url is when I try to search for data in the collection using my Spring MVC Java application. I get the following exception:

SEVERE: Servlet.service() for servlet [appServlet] in context with path [/smartwcm-admin] threw exception [Request processing failed; nested exception is org.apache.solr.client.solrj.impl.HttpSolrClient$RemoteSolrException: Error from server at http://localhost:8983/solr/#/swcm: Expected mime type application/xml but got text/html. <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01//EN" "http://www.w3.org/TR/html4/strict.dtd">

And the code I use is:

solrClient = new HttpSolrClient.Builder("http://localhost:8983/solr/#/swcm").build();
solrClient.setParser(new XMLResponseParser());
SolrQuery query = new SolrQuery();
query.setQuery("pageTitle:"+searchKey+"*);
query.setFields("webContentDefinitionId");
query.setStart(start);   
query.setRows(count);
query.set("defType", "edismax");
QueryResponse response = null;;
response = solrClient.query(query);
SolrDocumentList docList = response.getResults();

I am not sure what went wrong all of a sudden.


Solution

  • The problem is the # into your base url http://localhost:8983/solr/#/swcm.

    Try removing the misleading character:

    solrClient = new HttpSolrClient.Builder("http://localhost:8983/solr/swcm").build();
    

    I also suppose swcm is the name of your core/collection.

    But you can't use http://localhost:8983/solr/swcm directly into your browser, because this is the baseurl for all the requests.

    For example you can try with http://localhost:8983/solr/swcm/select?q=*:*&rows=10 which returns the first 10 documents in the swcm collection.

    To understand better how is composed a Solr url, I'll split the given example in the main parts:

    We can further break up the Solr Query in different parts:

    • In q=*:*, which is a common query used for return all the documents, q is the Query parameter, the former * means any available field name and the latter * stands for any value. q defines a query using standard query syntax. This parameter is mandatory.
    • rows=10 simply means returns 10 documents.