Custom field for Search API with multi values I'm using latest version of SearchAPI (1.18) and SearchAPI Solr (4.1.10).
I've a custom field that I want to have multiple values (I use it for faceted search with Facets module). In the previous version of SearchAPI the second example worked.
If I use this code, SearchAPI save &quot;Array&quot; as value:
&lt;?php

namespace Drupal\archivio_utils\Plugin\search_api\processor;

use Drupal\search_api\Datasource\DatasourceInterface;
use Drupal\search_api\Item\ItemInterface;
use Drupal\search_api\Processor\ProcessorPluginBase;
use Drupal\search_api\Processor\ProcessorProperty;

/**
 *
 * @SearchApiProcessor(
 *   id = &quot;periodo&quot;,
 *   label = @Translation(&quot;Periodo&quot;),
 *   description = @Translation(&quot;Periodo&quot;),
 *   stages = {
 *     &quot;add_properties&quot; = 0,
 *   },
 *   locked = true,
 *   hidden = false,
 * )
 */
class Periodo extends ProcessorPluginBase {

  /**
   * {@inheritdoc}
   */
  public function getPropertyDefinitions(DatasourceInterface $datasource = NULL) {
    $properties = [];

    if (!$datasource) {
      $definition = [
        'label' =&gt; $this-&gt;t('Periodo'),
        'description' =&gt; $this-&gt;t('Periodo'),
        'type' =&gt; 'string',
        'processor_id' =&gt; $this-&gt;getPluginId(),
      ];
      $properties['search_api_persona_periodo'] = new ProcessorProperty($definition);
    }

    return $properties;
  }

  /**
   * {@inheritdoc}
   */
  public function addFieldValues(ItemInterface $item) {
    $entity = $item-&gt;getOriginalObject()-&gt;getValue();
    /* @var \Drupal\node\Entity\Node $entity */
    /* @var \Drupal\node\Entity\Node $carriera */
    if ($entity-&gt;bundle() == 'persona') {
      $fields = $this-&gt;getFieldsHelper()
        -&gt;filterForPropertyPath($item-&gt;getFields(), NULL, 'search_api_persona_periodo');
      foreach ($fields as $field) {
        if (!$field-&gt;getDatasourceId()) {
          $values[] = 'test1';
          $values[] = 'test2';
          $field-&gt;addValue($values);
        }
      }
    }
  }
}

If I replace code where I wrote values with this:
$values[] = 'test1';
$values[] = 'test2';
foreach ($values as $value) {
   $field-&gt;addValue($value);
}

I obtain this error:

[error]  Drupal\search_api_solr\SearchApiSolrException while indexing
item entity:node/10008:it: Solr endpoint http://solr:8983/ bad request
(400). ERROR: [doc=3igm00-archivio_indice-entity:node/10008:it]
multiple values encountered for non multiValued field
ss_persona_periodo: [test1, test1] in
Drupal\search_api_solr\SolrConnector\SolrConnectorPluginBase-&gt;handleHttpException() (line 1016 of
/var/www/html/web/modules/contrib/search_api_solr/src/SolrConnector/SolrConnectorPluginBase.php).

How can I add multiple values to this custom field?
You can add this:
foreach ($fields as $field) {
    $field-&gt;addValue($custom_field);
    $field-&gt;addValue($custom_field);     
}