Solr Index appears to be valid - but returns no results

Viewed 15639

Solr newbie here.

I have created a Solr index and write a whole bunch of docs into it. I can see from the Solr admin page that the docs exist and the schema is fine as well. But when I perform a search using a test keyword I do not get any results back.

  1. On entering * : *

    into the query (in Solr admin page) I get all the results.

  2. However, when I enter any other query (e.g. a term or phrase) I get no results. I have verified that the field being queried is Indexed and contains the values I am searching for.

So I am confused what I am doing wrong.

5 Answers

I had the same issue with a new setup of Solr 8. The accepted answer is not valid anymore, because the <defaultSearchField> configuration will be deprecated.

As I found no answer to why Solr does not return results from any fields despite being indexed, I consulted the query documentation. What I found is the DisMax query parser:

The DisMax query parser is designed to process simple phrases (without complex syntax) entered by users and to search for individual terms across several fields using different weighting (boosts) based on the significance of each field. Additional options enable users to influence the score based on rules specific to each use case (independent of user input).

In contrast, the default Lucene parser only speaks about searching one field. So I gave DisMax a try and it worked very well!

Query example:

http://localhost:8983/solr/techproducts/select?defType=dismax&q=video

You can also specify which fields to search exactly to prevent unwanted side effects. Multiple fields are separated by spaces which translate to + in URLs:

http://localhost:8983/solr/techproducts/select?defType=dismax&q=video&qf=features+text

Last but not least, give the fields a weight:

http://localhost:8983/solr/techproducts/select?defType=dismax&q=video&qf=features^20.0+text^0.3

If you are using pysolr like I do, you can add those parameters to your search request like this:

results = solr.search('search term', **{
    'defType': 'dismax',
    'qf': 'features text'
})

In my case the problem was the format of the query. It seems that my setup, by default, was looking and an exact match to the entire value of the field. So, in order to get results if I was searching for the sit I had to query *sit*, i.e. use wildcards to get the expected result.

Related