3 min read

Opensearch Operation

Intergrate Directus content with an Opensearch cloud project or selfhosted project using Flows.
Opensearch Operation

Intergrate Directus content with an Opensearch cloud project or selfhosted project using Flows. This extension adds a new operation to your flows called Opensearch and uses an API key with full write access to create, update and delete documents in your search indexes. Opensearch operation is available via the Marketplace.

The operation is processed on the server side. If using localhost, Opensearch must be on the same server.

Usage

In a Flow, select the Opensearch as an operation, then populate the required fields. Here is detailed information on each field.


Field
TypeComments
HostURLFor cloud projects, the URL will look something like this: https://my-opensearch-project-a0123bc.es.reigon-1.aws.elastic.cloud. A local project will have a URL like this: http://localhost:9200
Force SSLbooleanRejects connection if SSL fails. Set to false if using self-signed certificates
UsernamestringThe username of the opensource instance
PasswordstringThe password for the opensource instance.
IndexstringThe identifier for the index. This is usually the collection such as the {{$trigger.collection}}variable.
ActionCreate, Read, Update or DeleteChoose the desired action for this request.
Item ID/Keystring, integer or an ArrayThe identifier for the item. Typically {{$trigger.key}} or {{$trigger.keys}}.
Item DatajsonThe content for this request. This can be {{$trigger.key}} or the output from another operation.

On Create

  1. Create a flow that is triggered on item.create and choose all the collection to include.
  2. Add the OpenSearch operation and set:
    • index to {{$trigger.collection}}
    • action to Create
    • item id/key to {{$trigger.key}}
    • item data to {{$trigger.payload}}.

On Update

  1. Create a flow that is triggered on item.update and choose all the collection to include.
  2. Add the OpenSearch operation and set:
    • index to {{$trigger.collection}}
    • action to Update
    • item id/key to {{$trigger.keys}}
    • item data to {{$trigger.payload}}.

On Delete

  1. Create a flow that is triggered on item.delete and choose all the collection to include.
  2. Add the OpenSearch operation and set:
    • index to {{$trigger.collection}}
    • action to Delete
    • item id/key to {{$trigger.keys}}

Manual Trigger

This is useful if you want to manually index items using a manual flow.

  1. Create a second flow that is triggered by another flow and set the Response body to the Data of the last operation.
  2. Add the OpenSearch operation and set:
    • index to {{$trigger.collection}}
    • action to Update
    • item id/key to {{$trigger.key}}
    • item data to {{$trigger.payload}}.
  3. Create a manual flow set the following:
    • choose the collections to include
    • location to Collection only
    • leave 'Required Selection' checked
  4. Add the Read Data operation with the following:
    • collection set to {{$trigger.body.collection}}
    • IDs set to {{$trigger.body.keys}}
  5. Create a Script operation to transform that data into valid payloads. Copy and paste the following:
module.exports = async function(data) {
	return Array.isArray(data['$last']) ? data['$last'].map((item) => {
    	return {
            collection: data['$trigger'].body.collection,
            key: item.id,
            payload: item,
        };
    }) : [
      {
        collection: data['$trigger'].body.collection,
        key: data['$last'].id,
        payload: data['$last'],
      }
    ];
}
  1. Create an operation that triggers another flow.
    • From the dropdown, cloose the flow created in step 1
    • Set the Iteration mode to serial
    • Set the Payload to {{$last}}

Now you can open any of the included collections and tick all the items to index, then click the flows icon (lightning bolt) from the right navigation bar and click the button. The label will match what you called the flow.

Check it out on NPM

@directus-labs/opensearch-operation
Intergrate Directus content with OpenSearch. . Latest version: 1.0.0, last published: a month ago. Start using @directus-labs/opensearch-operation in your project by running `npm i @directus-labs/opensearch-operation`. There are no other projects in the npm registry using @directus-labs/opensearch-operation.
Send me a coffee

By continuing to use our website, you consent to use essential cookies. We also use optional tracking cookies which help us gather statistics to improve our services. Do you consent to these cookies?

I Consent Do not track