Use Cases Requiring Modification of the Source Extension JSON Configuration

The Add extensions panel offers a JSON tab where you can see and modify the whole source extension configuration details (see JSON Tab). You can use this tab to help troubleshoot source extension configuration, but also to change the configuration.

The following table indicates specific indexing pipeline extension use cases that you can only achieve by modifying the source extension JSON configuration.

Note

You can easily apply an extension to a source from the Coveo Administration Console (see Apply an Extension to a Source), and then modify its JSON configuration rather than writing it from scratch.

Use case Description

Pass parameters

A good practice is to reuse indexing pipeline extensions across two or more sources to prevent creating and having to manage several similar script variants.

You may not be able to reuse an extension because the code needs information that varies from one source to another and that isn’t available in item metadata. In such a case, the usage of extension parameters could allow you to pass the variable information your code needs to be reusable.

In the JSON tab, you can include one or more parameters and their value such as Param1, Param2 and Value1, Value2 in the following source extension configuration sample:

{
  "common": {
    "preConversionExtensions": [
      {
        "condition": "",
        "extensionId": "myorg-vwrthh2s6lw5lcibrsut7cknsu",
        "parameters": {
          "Param1": "Value1",
          "param2": "Value2"
        },
        "versionId": "",
        "actionOnError": "SKIP_EXTENSION",
        "name": "NameOfMyExtension"
      }
    ],
    "postConversionExtensions": []
  },
  "items": {}
}

In your extension python script, you can get the passed parameter values from the parameters array.

# Getting `param1` and `param2` parameter values passed from the source extension configuration
a = parameters[`param1`]
b = parameters[`param2`]

# Adding metadata with these values
document.add_meta_data({`extparam1`:a,`extparam2`:b})

Execute a specific extension version

Each time you modify and save an extension, you create a new extension version. By default, the indexing pipeline uses the latest extension version.

In some cases, like when you actively develop and extension, you may want to temporarily apply the "stable" version of the extension, not the very last that you saved. You can get the extension version ID from the Extensions (platform-ca | platform-eu | platform-au) page.

In the JSON tab, you can specify the versionId parameter to force to use a specific extension version:

{
  "common": {
    "preConversionExtensions": [
      {
        "extensionId": "myorg-vwrthh2s6lw5lcibrsut7cknsu",
        "parameters": {},
        "versionId": "5XSihxzII4vsirD6jUlVlDeYIkz90z5U",
        "name": "NameOfMyExtension"
      }
    ],
    "postConversionExtensions": []
  },
  "items": {}
}

Action on error

You can use the optional actionOnError parameter to specify what to do when the extension returns an error.

The following table describes the available actionOnError parameter values:

Value Action when the extension returns an error

SKIP_EXTENSION

The extension is skipped for the item, as if it had never ran, and the item continues to be processed in the indexing pipeline. Default value.

REJECT_DOCUMENT

The item is rejected so it’s excluded from the index.

Use this value when the extension purpose is essential to the item searchability.

Example:

Your extension modifies item permissions. If the script returns and error, you can’t guarantee that the item permissions will be set correctly.

You want to ensure that you don’t create a security hole by making possibly sensitive information searchable by unauthorized users. You add "actionOnError": "REJECT_DOCUMENT" to the source extension JSON configuration.

{
  "common": {
    "preConversionExtensions": [
      {
        "extensionId": "myorg-retgvf2s6lw5lcibrsut7cknsu",
        "parameters": {},
        "actionOnError": "REJECT_DOCUMENT",
        "name": "SetPermissions"
      }
    ],
    "postConversionExtensions": []
  },
  "items": {}
}