Solr Error: need at least one suggestion

Errors

Solr could not build the suggester because its dictionary is empty: no document in the index has a value in the field the suggester reads from. Search keeps working. Only the autocomplete dictionary fails to build, and every build request returns HTTP 500.

What triggers the error

A build of the suggester: a request to /suggest with suggest.build=true or suggest.buildAll=true, or a commit when the suggester has buildOnCommit set to true. A suggester with lookupImpl FreeTextLookupFactory refuses to build from a field with no terms and Solr answers with java.lang.IllegalArgumentException: need at least one suggestion.

Check the field the suggester reads

Open solrconfig.xml (or solrconfig_extra.xml for Drupal) and find the field of each suggester. Then count the documents that carry that field. A result of 0 confirms the dictionary is empty.

curl "https://YOUR-SERVER/solr/YOUR_INDEX/select?q=YOUR_SUGGEST_FIELD:*&rows=0&wt=json"

Fix 1: put content into the suggester field

If you want autocomplete, index text into the field the suggester reads, then rebuild the suggester once. In Drupal with Search API Solr that field is twm_suggest, and it is filled only by Search API fields of type Suggester. Go to your Search API index, open Fields, add a short field such as the title with the type Suggester, save, and reindex the content.

Fix 2: stop building a suggester you do not use

If you do not use autocomplete, stop the build requests. In Drupal with Search API Solr, the cron sends suggest.buildAll=true after content changes, unless the suggest request handler is disabled. Go to Configuration › Search and metadata › Search API, open your Solr server, select the Request Handlers tab and disable the request_handler_suggest handlers. Outside Drupal, remove the suggester from your configuration, or set buildOnCommit to false and stop sending suggest.build.

<lst name="suggester">
  <str name="name">en</str>
  <str name="lookupImpl">FreeTextLookupFactory</str>
  <str name="dictionaryImpl">DocumentDictionaryFactory</str>
  <str name="field">twm_suggest</str>
  <str name="buildOnStartup">false</str>
  <str name="buildOnCommit">false</str>
</lst>

Upload the configuration and reload

After a configuration change, upload the changed files to your Opensolr Index and reload it. Then send one build request and check that /suggest answers with HTTP 200. To keep builds cheap once the dictionary has content, read Suggesters That Rebuild on Every Commit.

Related Solr errors