Timing out a query in Solr

16,766

As stated in Solr query continues after client disconnects? and written in the Solr FAQ

Internally, Solr does nothing to time out any requests -- it lets both updates and queries take however long they need to take to be processed fully.

But at the same spot in the FAQ is written

However, the servlet container being used to run Solr may impose arbitrary timeout limits on all requests. Please consult the documentation for your Serlvet container if you find that this value is too low. (In Jetty, the relevant setting is "maxIdleTime" which is in milliseconds)

So you may configure your container to close a long-running request so that the HTTPClients connected receive a shutdown.

However that may not be enough, Solr could internally still be working though, generating load on your Server. Therefore the common timeAllowed parameter may be used.

timeAllowed - This parameter specifies the amount of time, in milliseconds, allowed for a search to complete. If this time expires before the search is complete, any partial results will be returned.

Either with each request or configured as default in your solrconfig.xml.

<requestHandler name="standard" class="solr.StandardRequestHandler" default="true">
    <lst name="defaults">
        <!-- other parts left out -->
        <!-- timeout (in milliseconds) -->
        <int name="timeAllowed">5000</int>
    </lst>
</requestHandler>
Share:
16,766
Benjamin
Author by

Benjamin

Updated on July 30, 2022

Comments

  • Benjamin
    Benjamin almost 2 years

    I hitting queries to solr through a custom developed layer and few queries which i time out in my layer are still in the solr instance. Is there a parameter in solr which can be used to time out an particular query

  • Rougher
    Rougher about 8 years
    But what do I need to do if I don't want to get partial results?
  • cheffe
    cheffe about 8 years
    @Rougher so you want to prevent a timeout? That depends on your container (in case you still have one) or the configuration of your solr instance. Try it the other way around or ask a separate question :)
  • Rougher
    Rougher about 8 years
    I want timeout but without partial results. My container is Jetty (i use solr 5.4.1)
  • cheffe
    cheffe about 8 years
    IMHO that cannot be achieved. You cannot have both. But I would ask that on the mailing list or post a separate question here.
  • Apurv Nerlekar
    Apurv Nerlekar over 6 years
    @Rougher: timeout returns partial results, there is no mechanism to get timeout error or no results currently. You can keep a timeout in your application code itself which should be less than the solr query timeout fields. Once your application timeout is passed, just return error or 0 results in response and don't care about the partial results.