What's Actually Happening

Solr queries take too long to execute. Search response times are high, affecting application performance.

The Error You'll See

```bash $ curl "http://localhost:8983/solr/mycore/select?q=*:*"

# Response time > 5 seconds ```

Why This Happens

  1. 1.No proper schema optimization
  2. 2.Missing or inefficient indexes
  3. 3.Cache misconfiguration
  4. 4.Large result sets
  5. 5.Complex queries

Step 1: Check Query Performance

bash
curl "http://localhost:8983/solr/mycore/select?q=*:*&debugQuery=true"

Step 2: Check Index Stats

bash
curl "http://localhost:8983/solr/mycore/admin/luke"
curl "http://localhost:8983/solr/mycore/admin/stats"

Step 3: Optimize Schema

xml
<!-- schema.xml -->
<field name="title" type="text_general" indexed="true" stored="true"/>
<field name="content" type="text_general" indexed="true" stored="false"/>

Step 4: Configure Caches

xml
<!-- solrconfig.xml -->
<query>
  <filterCache class="solr.FastLRUCache" size="512" initialSize="512" autowarmCount="0"/>
  <queryResultCache class="solr.LRUCache" size="512" initialSize="512" autowarmCount="0"/>
  <documentCache class="solr.LRUCache" size="512" initialSize="512" autowarmCount="0"/>
</query>

Step 5: Use Filter Queries

bash
# Instead of:
q=title:search AND category:books
# Use:
q=title:search&fq=category:books

Step 6: Limit Fields

bash
# Only return needed fields
q=*:*&fl=id,title

Step 7: Use Pagination

bash
q=*:*&rows=10&start=0

Step 8: Commit and Optimize

bash
curl "http://localhost:8983/solr/mycore/update?commit=true"
curl "http://localhost:8983/solr/mycore/update?optimize=true"

Step 9: Check Resources

bash
free -m
top -bn1 | head -20

Step 10: Monitor Query Time

bash
curl "http://localhost:8983/solr/mycore/admin/mbeans?cat=QUERY&stats=true"
  • [Fix Solr Index Not Updating](/articles/fix-solr-index-not-updating)
  • [Fix Elasticsearch Query Timeout](/articles/fix-elasticsearch-query-timeout)