Since Solr 7.0 version all handlers return JSON format response. I know I can use <initParams> to configure default response format for known handlers. Though, I can't seem to apply <initParams> configuration to /admin/cores requests that are processed by a special handler CoreAdminHandler that is not defined in solrconfig.xml.
I tried adding <initParams> configuration mapping it to path /admin/cores but that had no effect.
<initParams path="/admin/cores">
<lst name="defaults">
<str name="wt">xml</str>
</lst>
</initParams>
I still get JSON response when I call /admin/cores?action=status.
Is it possible to influence response format for CoreAdminHandler requests via configuration?
Related
I am trying to get the more-like-this query parser working on my test system. The test system has SOLR cloud 6.5.0 installed. The MLT handler is enabled with the following configuration:
<requestHandler name="/mlt" class="solr.MoreLikeThisHandler">
<lst name="defaults">
<str name="mlt.qf">search_text_st</str>
<str name="mlt.fl">search_text_st</str>
<int name="mlt.minwl">4</int>
<int name="mlt.maxwl">18</int>
</lst>
</requestHandler>
When I query for document similar to a specific document with the handler, I get expected results. For example:
http://localhost:8983/solr/MyCloud/mlt?q=id:123
The above query will return results:
"response":{"numFound":361,"start":0,"maxScore":113.24594,"docs":[...]}
However, when I try an equivalent query using the MLTQParser with {!mlt qf=search_text_st fl=search_text_st minwl=4 maxwl=18}123, I get no results:
http://localhost:8983/solr/MyCloud/select?q=%7B!mlt+qf%3Dsearch_text_st+fl%3Dsearch_text_st+minwl%3D4+maxwl%3D18%7D123
The response looks like this:
"response":{"numFound":0,"start":0,"maxScore":0.0,"docs":[]}
I have done nothing so far to enable or configure MLTQParser, but it does appear to be enabled because I get an error when using a document ID that doesn't exist.
Any idea why this is not working?
I eventually figured out why this was failing. The search_text_st field was being created using copyField. The Cloud MLT Query Parser uses the realtime get handler to retrieve the fields to be mined for keywords. Because of the way the realtime get handler is implemented, it does not return data for fields populated using copyField. (see https://issues.apache.org/jira/browse/SOLR-3743)
Changing the configuration to use the source fields made it work.
I'm using Solr 4.10.
I have enabled the /export request handler for an index by adding this to the solrconfig.xml (as mentioned here: https://cwiki.apache.org/confluence/display/solr/Exporting+Result+Sets):
<requestHandler name="/export" class="solr.SearchHandler">
<lst name="invariants">
<str name="rq">{!xport}</str>
<str name="wt">xsort</str>
<str name="distrib">false</str>
</lst>
<arr name="components">
<str>query</str>
</arr>
</requestHandler>
Now I can use: http://localhost:8983/solr/index/select?.... as well as http://localhost:8983/solr/index/export?.... from a browser or curl.
But, I cannot get it to run properly using SolrJ.
I tried (as suggested here: https://lucene.apache.org/solr/4_10_0/solr-solrj/index.html):
SolrQuery query = new SolrQuery();
...
query.setRequestHandler("/export");
...
httpSolrServer.query(query);
The query now has a parameter &qt=export. It blew up giving me:
org.apache.solr.client.solrj.SolrServerException: Error executing query
More search suggested using SolrRequest instead of SolrQuery, I tried it:
SolrQuery query = new SolrQuery();
...
query.setRequestHandler("/export");
SolrRequest solrRequest = new QueryRequest(query);
httpSolrServer.request(solrRequest);
Now I get:
java.nio.charset.UnsupportedCharsetException: gzip
Any ideas?
---edit---
I found an option in httpSolrServer.request() to add a ResponseParser. I found 4 ResponseParsers. Tried them all, the only one that worked was NoOpResponseParser. Now I have the correct results, but dumped as a plain string in a single entry in a NamedList. I tried to parse it as JSON, but it's not in proper format. Each 30,000 document, there's a missing , !!!!.
I returned back to solrconfig.xml and changed wt in the /export handler from xsort to json. Now the response format has changed, but it's also not in proper format (data is incomplete) !!!!. And XML is not
supported.
I'm truly baffled.
I am using solr 4.8.1.
When I execute any query for testing purpose from Dashboard I get response in JSON(BY DEFAULT)
Can I change it and make XML as default.
Plz refer below screen.
I am taking about dashboard only.
Thanks for looking here.... :)
The default values for your requestHandlers (which is what responds when a query is sent to /query or /select etc.), is set in solrconfig.xml. Here's the example from example/solr in the distribution:
<!-- A request handler that returns indented JSON by default -->
<requestHandler name="/query" class="solr.SearchHandler">
<lst name="defaults">
<str name="echoParams">explicit</str>
<str name="wt">json</str>
<str name="indent">true</str>
<str name="df">text</str>
</lst>
</requestHandler>
Changing wt to xml will give you a requestHandler that returns it response as XML by default, unless overridden at query time with the wt parameter. There might be parts of the web interface that assumes the response will be json, but I'm pretty sure those supply a value for wt anyway.
I dont know if there is administration for web UI defaults, but you can change html easily:
in
solr-4.8.1\example\solr-webapp\webapp\tpl\query.html
change order of options
<select name="wt" id="wt" title="The writer type (response format).">
<option>xml</option>
<option>json</option>
<option>python</option>
<option>ruby</option>
<option>php</option>
<option>csv</option>
</select>
Whatever option you put on first will be default, or set it selected:
<option selected="selected">
You may also change this html in war file in solr-4.8.1\example\webapps.
Note that path is relative to example from 4.8.1 release
I am trying to Implement Apache Solr search through SolrNet library.So far I have managed to run an instance of Solr in my machine and make some queries based on specific fields.
My code to do it looks like this
var solr = ServiceLocator.Current.GetInstance<ISolrOperations<Product>>();
var results = solr.Query(new SolrQueryByField("id", "SP2514N"));
This one works fine now,But I would like to make queries with out specifying a field , So that when I enter a search key word solr will look in to the all fields available and return a result.I have Found the code to make it in SolrNet library from here
var solr = ServiceLocator.Current.GetInstance<ISolrOperations<Product>>();
var results = solr.Query(new SolrQuery("SP2514N"));
But this never worked,When I drilled down to bottom ,I found that I need to set default search fields in Solr instance so that Solr will search that fields when nothing else is selected(This is how i understood it I am not sure about this).
So I went to set default fields in Solr ,I took Solrconfig.XML and edited it like this
<requestHandler name="/query" class="solr.SearchHandler" default="true">
<lst name="defaults">
<str name="echoParams">explicit</str>
<str name="wt">json</str>
<str name="indent">true</str>
<str name="df">text</str>
<str name="df">id</str>
</lst>
</requestHandler>
[just added <str name="df">id</str> this field as extra].But this too never helped And I am stuck ,Can any one tell me How I could set default search field in Solr correctly?Or am i doing any thing else wrong?
I have Uploaded My Solrconfig file here
I do not know about SolrNet library, but to make a default field for search you need to define DefaultSearchField in schema.xml i.e. <defaultSearchField>FieldName</defaultSearchField>.
You can find this file # <SOLR_HOME>\apache-solr-3.6.0\example\example-DIH\solr\testsyndrome\conf\schema.xml
I hope that's what you are looking for.
Don't start from SolrNet, use Solr's built-in Web Admin interface. Iterate there until you understand the request handlers and the parameters. Then, go back to SolrNet.
In your case, it seems that you changed default request handler and tried to use df parameter twice. I would stick to the original request handler for now just to avoid the extra issue.
With using df parameter, are you trying to search a single field or multiple fields? If single field, keep only one value for the parameter. If multiple, you need to switch to using eDisMax, where you can provide a set of fields.
Again, admin interface lets you experiment with it, then you can add it into the handler's default parameter.
Is there a way to call one custom request handler from another in Solr. eg : i have /myhandler1 and /myhandler2 defined as custom request handlers in the solrconfig.xml. Defined like this
<requestHandler name="/my handler1" class="solr.CSVRequestHandler">
<lst name="defaults">
<str name="update.chain">mylogupdate</str>
<str name="stream.contentType">application/csv</str>
</lst>
</requestHandler>
and
<requestHandler name="/myhandler2" class="solr.CSVRequestHandler">
<lst name="defaults">
<str name="update.chain">mylogupdate</str>
<str name="stream.contentType">application/csv</str>
</lst>
</requestHandler>
is there a way to call /myhandler2 from /myhandler1. basically i want to use handler 1 to do some processing and then redirect it to another handler to do a second task.
the larger problem is this:
given a line like this ,
2012-01-04 23:11:41,450 AltQ:RCR-TRP: 101863261
i can split this on a comma separator and get two fields. i further want the second field to be split on a space separator and i want to store these values to different fields
like
val1:450
val2: altQ:RCR-TRP:
val3:101863261
and so on...
For the benefit of the ppl .. I still haven't found a way to redirect requests handlers..but the other problem however was solved . I found a work around to it by defining my own custom processor < that extends update request processor >
http://wiki.apache.org/solr/UpdateRequestProcessor#Processor_Customization_Examples
and i used JAVA to manipulate the document !