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.
Related
We've got a multilingual search index with the "field-per-language" configuration with a lot of similar aliases in the search handler like this:
<str name="f.content_en.qf">Title_en^10 Text_en^1 ...</str>
<str name="f.content_de.qf">Title_de^10 Text_de^1 ...</str>
...
They are used in the q parameter:
<str name="q">{!edismax qf=$searchField pf=$searchField v=$searchText}</str>
The client knows, which language should be used and calls Solr like this, e.g.: /solr/core/search?searchText=TEXT&searchField=content_en
That works fine, but the configuration contains a lot of similar stuff.
I'd like to optimize the config to something like this:
<str name="df">content</str>
<str name="f.content.qf">Title_${lang}^10 Text_${lang}^1...</str>
Then the client would need to provide the lang parameter only.
I tried to use concat function like this:
paramLang=en
searchFields=concat("Title", "_", "${paramLang}", " ", "Text", "_", "${paramLang}")
and use it as the qf:
q={!edismax qf=$searchFields v=$searchText}
But it seems, the local params qf does not support Solr functions.
Is is possible with Solr at all?
Actually, the Parameter substitution / Macro Expansion works fine.
The issue was with those macros in the solrconfig.xml: there is a conflict with Solr system properties substitution. Solr could not resolve the query parameter macros.
I could not find a proper way, how to escape query parameters (macros) and used the following workaround:
<lst name="invariants">
<str name="defType">edismax</str>
<str name="searchFields">
Title_${lang:${lang}}^10
Text_${lang:${lang}}^1
...
<lst name="defaults">
<str name="q">*</str>
<str name="qf">${searchFields:${searchFields}}</str>
<str name="pf">${searchFields:${searchFields}}</str>
<str name="lang">en</str>
...
Query URL: /search?q=TEXT&lang=en
Update: proper way to deal with var substitution in solrconfig.xml - escape the dollar char by $$:
<str name="searchFields">
Title_$${lang}^10
Text_$${lang}^1
...
Update #2: do NOT define macros in the invariant or append sections when using a Solr Cloud! Otherwise, you'll a weird exception, e.g.:
"undefined field: \"Text_$\"
or
"msg": "Error from server at null: org.apache.solr.search.SyntaxError: Query Field '${searchFields}' is not a valid field name"
P.S. wt=json as "invariant" is also NOT compatible with Solr Cloud, giving "unexpected" content-type error.
So many "surprises" :(
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.
We are trying to search collection Hidden from collection Front using the below url
http://localhost:8983/solr/Front/select?&q=hardware&wt=json&collection=Hidden
This results in the error QueryComponent.mergeIds as shown in the trace log below.
Querying the Hidden collection directly, returns expected results.
The /select handler for Front collection has the below default config.
<lst name="defaults">
<str name="echoParams">explicit</str>
<int name="rows">10</int>
<str name="qf">text</str>
<bool name="preferLocalShards">false</bool>
I have tried searching for the mergeIds related errors but couldnt find a solution.
Any suggestions would be welcome.
Trace Log
trace":"java.lang.NullPointerException\r\n\tat
org.apache.solr.handler.component.QueryComponent.mergeIds(QueryComponent.java:1115)\r\n\tat
org.apache.solr.handler.component.QueryComponent.handleRegularResponses(QueryComponent.java:759)\r\n\tat
org.apache.solr.handler.component.QueryComponent.handleResponses(QueryComponent.java:738)\r\n\tat
org.apache.solr.handler.component.SearchHandler.handleRequestBody(SearchHandler.java:426)\r\n\tat
org.apache.solr.handler.RequestHandlerBase.handleRequest(RequestHandlerBase.java:156)\r\n\tat
org.apache.solr.core.SolrCore.execute(SolrCore.java:2036)\r\n\tat
org.apache.solr.servlet.HttpSolrCall.execute(HttpSolrCall.java:657)\r\n\tat
org.apache.solr.servlet.HttpSolrCall.call(HttpSolrCall.java:464)\r\n\tat
org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:257)\r\n\tat
org.apache.solr.servlet.SolrDispatchFilter.doFilter(SolrDispatchFilter.java:208)\r\n\tat
org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1668)\r\n\tat
org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:581)\r\n\tat
org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143)\r\n\tat
org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:548)\r\n\tat
org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:226)\r\n\tat
org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1160)\r\n\tat
org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:511)\r\n\tat
org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:185)\r\n\tat
org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1092)\r\n\tat
org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141)\r\n\tat
org.eclipse.jetty.server.handler.ContextHandlerCollection.handle(ContextHandlerCollection.java:213)\r\n\tat
org.eclipse.jetty.server.handler.HandlerCollection.handle(HandlerCollection.java:119)\r\n\tat
org.eclipse.jetty.server.handler.HandlerWrapper.handle(HandlerWrapper.java:134)\r\n\tat
org.eclipse.jetty.server.Server.handle(Server.java:518)\r\n\tat
org.eclipse.jetty.server.HttpChannel.handle(HttpChannel.java:308)\r\n\tat
org.eclipse.jetty.server.HttpConnection.onFillable(HttpConnection.java:244)\r\n\tat
org.eclipse.jetty.io.AbstractConnection$ReadCallback.succeeded(AbstractConnection.java:273)\r\n\tat
org.eclipse.jetty.io.FillInterest.fillable(FillInterest.java:95)\r\n\tat
org.eclipse.jetty.io.SelectChannelEndPoint$2.run(SelectChannelEndPoint.java:93)\r\n\tat
org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.produceAndRun(ExecuteProduceConsume.java:246)\r\n\tat
org.eclipse.jetty.util.thread.strategy.ExecuteProduceConsume.run(ExecuteProduceConsume.java:156)\r\n\tat
org.eclipse.jetty.util.thread.QueuedThreadPool.runJob(QueuedThreadPool.java:654)\r\n\tat
org.eclipse.jetty.util.thread.QueuedThreadPool$3.run(QueuedThreadPool.java:572)\r\n\tat
java.lang.Thread.run(Unknown Source)\r\n",
You cannot search in different collection as you tried before. each collection will have different config files. so your FRONT collection has /select handler which can request and get results from only FRONT collection not from Hidden.
In case if you want to use results from other collection index, you should use cross Join.
check this link
Hi i am using a slorj api to query solr indexes. But i am getting some exception when i add following query to SolrQuery object.
When i run following query in browser it is working fine
http://localhost:8983/solr/hellosolr/select?q=fkey:book+OR+bookstore+AND+whword:what&fl=fanswer
it is working fine but when i run the same query using SolrQuery i am getting following exception
SolrQuery solrQuery = new SolrQuery();
solrQuery.set("q", "fkey:book+OR+bookstore+AND+whword:what");
solrQuery.set("fl", "fanswer");
Exception-
org.apache.solr.client.solrj.impl.HttpSolrClient$RemoteSolrException: Error from server at http://localhost:8983/solr/hellosolr: org.apache.solr.search.SyntaxError: Cannot parse 'fkey:book+OR+bookstore+AND+whword:what': Encountered " ":" ": "" at line 1, column 39.
Was expecting one of:
<EOF>
<AND> ...
<OR> ...
<NOT> ...
"+" ...
Please tell me how i can write above html query using SolrQuery java api.
Your error message is a syntax error. Take out the + signs.
For the exception, try this query instead:
(fkey:book OR fkey:bookstore) AND whword:what
or you can write it like this (note the parentheses):
(fkey:book bookstore) AND whword:what
If you have OR defined as your default, then Solr will insert it between book and bookstore for you. Otherwise it will do an AND. I believe OR is the default. Check your solrconfig.xml to be sure.
If you don't specify a field in front of a search term, Solr will use the default field (it's text in my version, for example). If Solr can't find it, you'll get the undefined field [name] error.
Now, why your bad query is working from the admin panel, I don't know, but this should solve your SolrJ problem.
Assuming you're using the /select handler, you can go to solrconfig.xml and change the default:
<requestHandler name="/select" class="solr.SearchHandler">
<lst name="defaults">
<str name="echoParams">explicit</str>
<int name="rows">10</int>
<str name="df">blah</str>
</lst>
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