How can I execute a RealTime get request from the SolrJ client?
I specifically need to retrieve un-commited documents in order to check the _version_ field for optimistic concurrency.
Since the RealTime Get is implemented with an alternate requestHandler, you would just need to use the setRequestHandler() method on SolrQuery passing "/get" as the handler name.
Please see the testRealTimeGet() method in this SolrExampleTests.java file from the Solr source for a full example.
Here is the snippet from that file:
SolrQuery q = new SolrQuery();
q.setRequestHandler("/get");
q.set("id", "DOCID");
q.set("fl", "id,name,aaa:[value v=aaa]");
Related
How can I query Solr, using the HTTP API, for information about a collection? I'm not talking about the collection's indexes, which I could query using the COLSTATUS command. I'm just talking about the basic details of a collection, which you can see when you click on a collection in the Solr web admin page, such as config name.
When wondering where information provided in the web interface comes from, the easiest way is to bring up your browser's development tools and go to the Network section. Since the interface is a small Javascript application, it uses the available REST API in the background - the same that you'd query yourself.
Extensive collection information can be retrieved by querying:
/solr/admin/collections?action=CLUSTERSTATUS&wt=json
(Any _ parameter is just present for cache busting).
This will return a list of all the collections present and their metadata, such as which config set they use and what shards the collection consists of. This is the same API endpoint that the web interface uses.
collections":{
"aaaaa":{
"pullReplicas":"0",
"replicationFactor":"1",
"shards":{"shard1":{
"range":"80000000-7fffffff",
"state":"active",
"replicas":{"core_node2":{
"core":"aaaaa_shard1_replica_n1",
"base_url":"http://...:8983/solr",
"node_name":"...:8983_solr",
"state":"down",
"type":"NRT",
"force_set_state":"false",
"leader":"true"}}}},
"router":{"name":"compositeId"},
"maxShardsPerNode":"1",
"autoAddReplicas":"false",
"nrtReplicas":"1",
"tlogReplicas":"0",
"znodeVersion":7,
"configName":"_default"},
...
}
Please try the below code.
getConfigName(String collectionName){
//provide the list of zookeeper instances
List<String> zkHosts = ""
// get the solr cloud client
CloudSolrClient cloudSolrClient = new CloudSolrClient.Builder (zkHosts, Optional.empty
()).build ();
// get the config for the collection
String configName = solrConnectionProvider.getCloudSolrClient().getZkStateReader().readConfigName(collectionName);
return configName;
}
Please handle the exception(s) from your end.
Is it possible to get the query configuration values(default + request parameters) using SolrJ ?
For example: If I direct a request to the RequestHandler using SolrJ, I would like to get a list of parameters(default + overridden request parameters) used on the query. I need this to log the current configuration when the query was made.
Try adding the parameter echoParams=all.
The echoParams parameter tells Solr what kinds of Request parameters
should be included in the response for debugging purposes, legal
values include:
none - don't include any request parameters for debugging
explicit -
include the parameters explicitly specified by the client in the
request
all - include all parameters involved in this request, either
specified explicitly by the client, or implicit because of the request
handler configuration.
Take a look at Common Query Parameters
Given a QueryResponse object (SolrJ 3.6.2), is there any way to retrieve the query that was made to get that response other than parsing the query string?
QueryResponse exposes the Header information from which the q can be retrieved.
rsp.getHeader().get("q")
QueryResponse exposes the Header information from which the q can be retrieved. But it cant be directly retrived directly as mentioned by Jayendra.
You need to use:
response.getHeader().get("params");
This will give you a result like:
{start=0,q=apple,qf=name^10.0 description^5.0,version=2,rows=10,defType=edismax}
There you can see your result.
I'm reading sunspot documentation and find that sunspot based on RSolr library.
Is there any way to get connection to perform low level request like this
pseudo-code:
solr = Sunspot.connection
response = solr.get 'select', :params => {:q => '*:*'}
Not as of the current version (1.3.2). Well, you can, but you'd have to instance_eval a few objects to get to the underlying RSolr object. Patches are welcome at http://github.com/sunspot/sunspot — a good accessor method for the RSolr connection would be welcome.
It looks like the QueryResponse from Solrj has no mean to give you a quoted Json string with wt=on or not. All I received is something like this
{responseHeader={status=0,QTime=2,params= {fl=id,productName,imageFront,priceEng,priceEngExp...
Question:
1) Am I missing something here ? Or there is no way to get the json response properly from the Solr server by Solrj.
2) Now on my client, if I convert the non-quoted json string from Solrj, does it mean it was done two times, once in server time and one in the Solrj client time ?
You can get JSON response by setting wt=json to the Solr query. Example URL is shown below :
localhost:8983/solr/select/?q=:&rows=10&indent=on&wt=json
You can't get JSON response using Solrj. You don't need to use Solrj for this purpose.By sending HTTP requests to the URL above, you can get json response.
With newer versions of Solr (starting with 4.7.0) it is possible to return the query response directly in json-format. This can be done with the NoOpResponseParser.
SolrQuery query = new SolrQuery();
QueryRequest req = new QueryRequest(query);
NoOpResponseParser rawJsonResponseParser = new NoOpResponseParser();
rawJsonResponseParser.setWriterType("json");
req.setResponseParser(rawJsonResponseParser);
NamedList<Object> resp = mySolrClient.request(req);
String jsonResponse = (String) resp.get("response");
System.out.println(jsonResponse );