Retrieve schema info from HttpSolrServer and CloudSolrServer with SolrJ - solr

HttpSolrServer/CloudSolrServer support the /schema request handler but that isn't supported on the EmbeddedSolrServer and I would like a way to access the same information using SolrJ (and without HTTP requests).
When using EmbeddedSolrServer, the instance is created by passing a CoreContainer to the constructor. Later, the CoreContainer can be queried for all (well, just the one in the case of an embedded server) SolrCores with the getCores() method. From any given SolrCore I can obtain its schema using getSchema().
I now want to do the same thing but with an HttpSolrServer server and a CloudSolrServer. They, however, don't seem to have a way to ask for the list of loaded SolrCores or CoreContainers or anything. I know about the CoreAdmin but that only retrieves the status of each core, with no way to get Java instances of SolrCore.
Is it possible to obtain a list of SolrCores from a HttpSolrServer/CloudSolrServer using SolrJ, and how is it done?

Since Solr 5.3 SolrJ has API for Schema Access - see SchemaRequest.
For example, to retrieve collection schema one can use (in Solr 7) :
CloudSolrClient client = ...;
SchemaRequest request = new SchemaRequest();
SchemaResponse response = request.process(client, "collectionName");
SchemaRepresentation schema = response.getSchemaRepresentation();

Related

How to Ignore a Missing Field in Solr Request Parameters API?

I have an old solr instance that has enabled a customer parameter in the json API, e.g.
?json.customParam="eeebc"
In order to upgrade Solr to a new version (on a new machine), I simply want to ignore it instead of solr returning an exception so some level of backward compatibility is possible. The current exception is:
Unknown top-level key in JSON request: customParam
I'm hoping there is some fairly simple way to just ignore that parameter using the schema/solrconfig etc.

How to access Aache SOLR custom request handler /suggest from solrj or spring data for solr?

I'm new to Solr. I'm implementing auto complete functionality for my application. I have configured the required fields in solr and created a custom request handler /suggest. I'm finding it tricky to access it via solr java client solrj. I'm even fine with the spring data for solr. Please somebody help to access my custom request handler from solr java client.
With spring-data-solr you might add #Query(requestHandler = "/suggest") or use query.setRequestHandler("/suggest").
In case you're doing autocomplete you might also give /terms and the SimpleTermsQuery a try.
SolrJ supports this through the use of the setRequestHandler method on the SolrQuery class.

how to implement solr to index mysql database in java?

i want to use solr to index MySql database and so that I can perform a faster search of data on my website.Can anyone help me with the code. I don't have any idea how to implement solr in my code.
Your question is too broad. However for a head start you could have a look at DataImport in Solr.
you many want to check for Solr Data Import Handler module which will help you index data from MySQL into Solr without writing any java code.
If you have downloaded Solr, You can check out the example solr-4.3.0/example/example-DIH (Refer to the readme.txt) which will give you an idea of how the DIH is configured and the indexing can be done.
CommonsHttpSolrServer commonsHttpSolrServer = new CommonsHttpSolrServer("http://localhost:8983/solr");
QueryRequest request = new QueryRequest(params);
request.setPath("/dataimport");
ModifiableSolrParams params = new ModifiableSolrParams();
params.set("command", "full-import");
commonsHttpSolrServer.request(request);
NOTE - The request sent is asynchronous, so you would receive an immediate response and would need to check the status to know if it was complete.

What is the default address of Solr Server (Solr 4.0) for use from a SolrJ client

I'm trying to connect with Solr Server from a SolrJ client, but it gives an HTTPResponse Exception.
Here's my code:
SolrServer server = new HttpSolrServer("http://"localhost":8983/solr/");
Here's the exception:
java.lang.NoClassDefFoundError: org/apache/http/NoHttpResponseException:
Does Solr have a default address? Where can you find it?
I am not familiar with SolrJ - but the endpoint seems to be missing the core name to me.
You would need to point your Solr client to a particular core.
The URI for the core would look like this (for reloading core command)
http://localhost:8983/solr/{{solrCoreName}}
The admin UI should be accessible at
http://localhost:8983/solr
By default, Solr will start on port 8983. That can be changed though. You can change that for example in the solr.in.sh file using the SOLR_PORT property.

How to make queries and send them to solr

I want to make queries according to the parameters I get from my server and query solr server.
First I want a guide how to make a query url and second, how to send it to solr. For the time being I use the default graphical user interface.
Use Client Libraries provided with Solr in your application to build queries as you get from the browser and request it to solr.
These libraries provide the Solr results in the respective language objects, which are very simple to use.
Solrj for Java, Sunspot and rsolr with Ruby, SolrPHP for PHP and much more
As I came to know from your other comment, you are using C#.
Here you go, code snippet for fetching the XML in Solr using C#
using System.Net;
...
...
HttpWebRequest webrequest = (HttpWebRequest)HttpWebRequest.Create(solruri);
webrequest.Method = WebRequestMethods.Http.Get;
//Get the Response from Solr
HttpWebResponse webresponse = (HttpWebResponse)webrequest.GetResponse();
StreamReader reader = new StreamReader(webresponse.GetResponseStream());
Variable solruri= url to Solr instance running, for example: _http://localhost:8080/solr/select......

Resources