How do I sort the field value by null in Search API Solr? I want to alter the search API Solr query in Drupal 8 to order by field null in hook_search_api_solr_query_alter(). How do I add my sort expression in the Solr search query? Do I need to add it in hook_views_query_alter()?
I also had this issue, I couldn't find an easy way to sort by null in a query alter (although Solr does have sortMissingLast, I just couldn't figure out how to inject it through Search API). Instead, I added a processor to check the field in question and add another field to identify whether it's there or not. Then you can sort by that.

&lt;?php

namespace Drupal\my_module\Plugin\search_api\processor;

use Drupal\Core\Annotation\Translation;
use Drupal\search_api\Annotation\SearchApiProcessor;
use Drupal\search_api\Datasource\DatasourceInterface;
use Drupal\search_api\Item\ItemInterface;
use Drupal\search_api\Processor\ProcessorPluginBase;
use Drupal\search_api\Processor\ProcessorProperty;

/**
 * Checks for my field.
 *
 * @SearchApiProcessor(
 *   id = "my_field_null",
 *   label = @Translation("Has My Field"),
 *   description = @Translation("Adds a check for null field to index."),
 *   stages = {
 *     "add_properties" = 0,
 *   },
 *   locked = true,
 *   hidden = false,
 * )
 */
class MyFieldNull extends ProcessorPluginBase {

  /**
   * Machine name of the processor.
   * @var string
   */
  protected $processor_id = 'my_field_null';

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

    if (!$datasource) {
      $definition = [
        'label' =&gt; $this-&gt;t('Has My Field'),
        'description' =&gt; $this-&gt;t('Does this have my field?'),
        'type' =&gt; 'string',
        'processor_id' =&gt; $this-&gt;getPluginId(),
      ];
      $properties[$this-&gt;processor_id] = new ProcessorProperty($definition);
    }

    return $properties;
  }

  /**
   * {@inheritdoc}
   */
  public function addFieldValues(ItemInterface $item) {
    $entity = $item-&gt;getOriginalObject()-&gt;getValue();
    if (method_exists($entity, 'hasField') &amp;&amp; $entity-&gt;hasField('field_my_field')) {
      $has_field = TRUE;
    }
    else {
      $has_field = FALSE;
    }

    $fields = $this-&gt;getFieldsHelper()
      -&gt;filterForPropertyPath($item-&gt;getFields(), NULL, $this-&gt;processor_id);

    foreach ($fields as $field) {
      $field-&gt;addValue($has_field);
    }
  }

}