Skip to main content

Having updated Solr, re-indexing wasn't working. The error in the logs was

Drupal\search_api_solr\SearchApiSolrException while indexing item entity:node/2386:en: Solr endpoint http://127.0.0.1:8983/ bad request (code: 400, body: Exception writing document id 36lk64-related_projects-entity:node/2386:en to the index; possible analysis error: cannot change field "tm_X3b_en_body" from index options=DOCS_AND_FREQS_AND_POSITIONS to inconsistent index options=DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS, message: Solr HTTP error: OK (400) { "responseHeader":{ "status":400, "QTime":1}, "error":{ "metadata":[ "error-class","org.apache.solr.common.SolrException", "root-error-class","java.lang.IllegalArgumentException"], "msg":"Exception writing document id 36lk64-related_projects-entity:node/2386:en to the index; possible analysis error: cannot change field \"tm_X3b_en_body\" from index options=DOCS_AND_FREQS_AND_POSITIONS to inconsistent index options=DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS", "code":400}} ). in Drupal\search_api_solr\SolrConnector\SolrConnectorPluginBase->handleHttpException() (line 1149 of /var/www/html/{name}/modules/contrib/search_api_solr/src/SolrConnector/SolrConnectorPluginBase.php).

The error message indicates that there's an issue with the Solr configuration related to the field "tm_X3b_en_body." It seems that there's an attempt to change the field's index options from "DOCS_AND_FREQS_AND_POSITIONS" to "DOCS_AND_FREQS_AND_POSITIONS_AND_OFFSETS," which is not allowed.

To add the new field <field name="tm_X3b_en_body" type="text_general" indexed="true" stored="true"/> to the Solr schema.xml file, you need to find the appropriate location within the <schema> section. Typically, fields are listed within the <fields> section of the schema. If your schema doesn't have a <fields> section, you should add it.

In the schema.xml file there was no mention of the string 'tm_X3b_en_body'.  So I need to add it in.

 

Adjusting the schema.xml file

Note: Always make a backup of your configuration files before making changes to them.

How you can add the new field to your schema.xml file:

Open your schema.xml file in a text editor.

Locate the <fields> section within the <schema> tag.

Add the new field definition within the <fields> section:

<fields>
  <!-- Other fields may already exist here -->
  <!-- Add the new field definition -->
  <field name="tm_X3b_en_body" type="text_general" indexed="true" stored="true"/>
  <!-- Other fields may already exist here -->
</fields>
If the <fields> section doesn't exist, you can add it right after the <schema> tag:
xml
Copy code
<schema name="drupal-4.3.2-solr-8.x-0" version="1.6">
  <!-- Other schema configurations -->
  <!-- Add the <fields> section with the new field definition -->
  <fields>
     <field name="tm_X3b_en_body" type="text_general" indexed="true" stored="true"/>
     <!-- Other fields may be added here -->
  </fields>
  <!-- Other schema configurations -->
</schema>

Save the schema.xml file.  Make sure to adapt the placement based on your schema structure. Once the file is saved, you can restart Solr to apply the changes.

Post this change, Solr was restarted and confirmed by checking the status.

Adding the above code to the schema.xml file resulted in the following error

{core name}: org.apache.solr.common.SolrException:org.apache.solr.common.SolrException: Could not load conf for core production: Can't load schema /var/solr/data/{core-name}/conf/schema.xml: Unknown fieldType 'text_general' specified on field tm_X3b_en_body
Please check your logs for more information

The error indicates that Solr is unable to load the schema due to an unknown fieldType 'text_general' specified on the field tm_X3b_en_body. This typically means that the 'text_general' fieldType is not defined in your Solr configuration.

To resolve this issue, you should define the 'text_general' fieldType in your schema.xml file. You can either define it explicitly or choose an existing fieldType that suits your needs.

The adjusted schema.xml file

<!-- Other schema configurations -->
 <!-- Add the <types> section with the 'text_general' fieldType -->
  <types>
     <!-- Other field types may already exist here -->
     <!-- Add the 'text_general' fieldType -->
     <fieldType name="text_general" class="solr.TextField" positionIncrementGap="100">
        <analyzer type="index">
           <tokenizer class="solr.StandardTokenizerFactory"/>
           <filter class="solr.LowerCaseFilterFactory"/>
        </analyzer>
        <analyzer type="query">
           <tokenizer class="solr.StandardTokenizerFactory"/>
           <filter class="solr.LowerCaseFilterFactory"/>
        </analyzer>
     </fieldType>
     <!-- Other field types may already exist here -->
  </types>
  <!-- Add the <fields> section with the new field definition -->
  <fields>
     <field name="tm_X3b_en_body" type="text_general" indexed="true" stored="true"/>
     <!-- Other fields may be added here -->
  </fields>

Once adjust restart Solr and check the status

To restart the Solr service

sudo systemctl restart solr

 

To verify the status of the Solr service

sudo systemctl status solr

 

 

MultiValued error

Drupal\search_api_solr\SearchApiSolrException while indexing item entity:node/23001:en: Solr endpoint http://localhost:8983/ bad request (code: 400, body: ERROR: [doc=36lk64-{name}-entity:node/23001:en] multiple values encountered for non multiValued field tm_X3b_en_category: [Commercial Wildcatch, Aquaculture], message: Solr HTTP error: OK (400) { "responseHeader":{ "status":400, "QTime":1}, "error":{ "metadata":[ "error-class","org.apache.solr.common.SolrException", "root-error-class","org.apache.solr.common.SolrException"], "msg":"ERROR: [doc=36lk64-{name}-entity:node/23001:en] multiple values encountered for non multiValued field tm_X3b_en_category: [Commercial Wildcatch, Aquaculture]", "code":400}} ). in Drupal\search_api_solr\SolrConnector\SolrConnectorPluginBase->handleHttpException() (line 1149 of /var/www/html/{name}/modules/contrib/search_api_solr/src/SolrConnector/SolrConnectorPluginBase.php).

The current issue diverges slightly from the prior error. Given that the category field utilizes taxonomy, it accommodates multiple values. Consequently, an extra attribute must be incorporated:

<field name="tocngramstringm_X3b_en_field_objectives" type="text_general" multiValued="true" indexed="true" stored="true"/>

This complete line signifies the adjustment, introducing the multiValued="true" attribute to accommodate the field's capacity for multiple values.

 

Related articles