Allow a Server plugin to say it doesn't support adding, removing indexes

Created on 12 June 2025, 12 days ago

Problem/Motivation

Currently, the Search API Server Task Manager assumes that it can add, update, and remove Indexes on its own (see \Drupal\search_api\Task\ServerTaskManager::getSupportedTypes()). But, it may not be possible (or cost-effective) to grant Search API permission to do all of those things on a Server.

For example, suppose an organization wants to connect Search API to an Index on a Server that they are already using for something else. They don't want to risk a Drupal mis-configuration breaking their existing Indexes, so they only grant the Drupal team credentials to update the index, i.e.: not add or remove the index.

While the backend-specific code can simply choose not to send certain commands (see the merge request in [#3522107], specifically the code paths where self_manage_indexes is disabled), the backend-specific code has no control over what Server Tasks that Search API queues up for that Server: if, for example, addIndex or removeIndex Server Tasks are added to that Server's queue, the index will be unusable until they complete successfully, which will never happen.

(note that [#3529273] has a patch to show the Server Tasks that are queued for a particular Search API Server)

Steps to reproduce

  1. Sign up for a trial of Elastic Cloud Serverless
  2. Create an Elasticsearch Index from /app/elasticsearch/content/search_indices/new_index/api, I called mine mparker17_test_index (if you choose a different name, only use underscores in the index name). Note the Elasticsearch Endpoint (which looks like a URL) from the Index's Overview page.
  3. Create an access key from /app/management/security/api_keys/create, and note the key. Grant it the following permissions...
    {
      "role-a": {
        "cluster": [ "all" ],
        "indices": [
          { "names": [ "mparker17_test_index" ], "privileges": [ "all" ], "allow_restricted_indices": false }
        ],
        "applications": [],
        "run_as": [],
        "metadata": {},
        "transient_metadata": { "enabled": true }
      }
    }
        
  4. Set up a Drupal site with elasticsearch_connector-8.0.x, and apply the patch from Connect to an Elastic Cloud Hosted Deployment acting as a Search API Server by entering a Cloud ID and API key Active to elasticsearch_connector. Elasticsearch Connector 8.0.x will automatically install search_api. Optionally, apply the patch from Show which Server Tasks are pending on Server view page Active to search_api. Also install key-8.x-1.20 .
  5. Set up a new Authentication key, whose value is the access key you created in step 3.
  6. Create a new Search API Server whose Backend is ElasticSearch, and whose ElasticSearch Connector is either Elastic Cloud Endpoint. Enter the Elasticsearch Endpoint from the Index you created in step 2, and select the Authentication key you set up in the previous step. Make sure that "Mange indexes on this server" is unchecked. Click "Save".
  7. Create a new Search API Index with the same machine name as the Index you created in step 2; and whose Server is the one you set up in the previous step.
  8. Go back to the Server's "View" page. Note that there is 1 pending server task (if you installed the patch from 3529273, it will tell you that it's a task of type addIndex).
  9. Try clicking "Execute tasks now". Note you get an error.

Proposed resolution

Allow Servers to say which kinds of Server Tasks they support.

Don't queue Server Tasks that aren't supported by the server.

Remaining tasks

  1. Write a patch
  2. Review and feedback
  3. RTBC and feedback
  4. Commit
  5. Release
Feature request
Status

Active

Version

1.0

Component

General code

Created by

🇨🇦Canada mparker17 UTC-4

Live updates comments and jobs are added and updated live.
Sign in to follow issues

Comments & Activities

Production build 0.71.5 2024