Learn more about our ✨ new ✨ native MCP
Directus Logo
  • Use Cases and Features
    • Headless CMS
      Manage and deliver content with ease
    • Backend-as-a-Service
      Build and ship applications faster
    • Headless Commerce
      A single source of truth for products
    • 100+ More Use Cases
      Build anything (or everything)
    • Instant APIs
      Connect a database, get REST + GraphQL APIs
    • Granular Policy-Based Auth
      Provide secure, autonomous data access
    • Visual Automation Builder
      Automate content and data workflows with ease
    • 50+ More Features
      Get everything you need out-of-the-box
    Project Showcase
    Built With Directus

    Built With Directus

    See what everyone's been building with Directus

  • Learn More
    • Blog
      Read our latest articles and guides
    • Case Studies
      Case studies and success stories
    • Community
      Join our new community forum.
    • Agency Directory
      Browse our list of agency partners
    • About Us
      Learn more about Directus and the team
    • Wall of Love
      See what others are saying about us
    • Contact
      Have a general inquiry or question for us?
    • Support
      Reach out to Directus support
    Watch Directus TV
    Directus TV
    Video

    Directus TV

    Go down the rabbit hole with hours of original video content from our team.

  • Developers
  • Enterprise
  • Pricing
Book a DemoGet StartedLog In
GitHub logo33,618
Directus Marketplace
Marketplace
  1. Extensions
  2. Integrations
  3. Templates
Back to Extensions
operation

Elasticsearch Operation

Intergrate Directus content with Elasticsearch.

Elasticsearch Operation

Intergrate Directus content with Elasticsearch.

Elasticsearch Operation Banner

Requirements

  • An Elasticsearch cloud project or selfhosted project with access to the API.
  • An API key with full write access.

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

Installation

Refer to the Official Guide for details on installing the extension from the Marketplace or manually.

Usage

Once installed, select the Elasticsearch as an operation in the flow, then required values into the fields provided. Here is detailed information on each field.

Field Type Comments
Host URL For cloud projects, the URL will look something like this: https://my-elasticsearch-project-a0123bc.es.reigon-1.aws.elastic.cloud. A local project will have a URL like this: http://localhost:9200
API Key string Create the API in the cloud project or fetch the API key from your local env for Elasticsearch.
Index string The identifier for the index. This is usually the collection such as the {{$trigger.collection}} variable.
Action Create, Read, Update or Delete Choose the desired action for this request.
Item ID/Key string, integer or an Array The identifier for the item. Typically {{$trigger.key}} or {{$trigger.keys}}.
Item Data json The 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 Elasticsearch 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 Elasticsearch 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 Elasticsearch 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 Elasticsearch 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.

@directus-labs/elasticsearch-operation

npm i @directus-labs/elasticsearch-operation
This extension is not sandboxed and can only be installed in self-hosted instances using npm. Learn more.
Mike Elsmore
Mike Elsmore
Verified
1.0.0
Works with v11.0.0+
Updated 8 months ago
MIT License
1.1 MiB (4 files)
npm
  • Directus LogoDirectus Logo

    A composable backend to build your Headless CMS, BaaS, and more. 

  • Solutions
    • Headless CMS
    • Backend-as-a-Service
    • Product Information
    • 100+ Things to Build
  • Resources
    • Documentation
    • Guides
    • Community
    • Release Notes
  • Support
    • Issue Tracker
    • Feature Requests
    • Community Chat
    • Cloud Dashboard
  • Organization
    • About
    • Careers
    • Brand Assets
    • Contact
©2025 Monospace Inc
  • Cloud Policies
  • License
  • Terms
  • Privacy