OpenSearch icon

OpenSearch

Consume the OpenSearch API

Actions9

Overview

This node integrates with the OpenSearch API to manage indices and documents within an OpenSearch cluster. Specifically, the "Index - Create" operation allows users to create a new index with customizable settings, mappings, and aliases. This is useful for setting up new data structures in OpenSearch before indexing documents.

Common scenarios include:

  • Creating a new index tailored to specific data requirements, such as defining custom field mappings or shard settings.
  • Setting up aliases for easier query routing or index management.
  • Configuring index-level options like timeouts and shard activation behavior.

Practical example:

  • A user wants to create an index named "products" with 3 shards and 2 replicas, define mappings for product fields (e.g., name as text, price as double), and assign aliases for different query contexts.

Properties

Name Meaning
Index ID The unique identifier (name) of the index to create.
Aliases JSON object defining index aliases, which are alternative names or filters for the index. See OpenSearch aliases documentation.
Include Type Name Boolean flag indicating whether a mapping type is expected in the mappings body. Defaults to false.
Mappings JSON object specifying the field mappings for the index, defining data types and structure. See OpenSearch mapping documentation.
Master Timeout Time period to wait for connection to the master node before failing. Default is "1m" (one minute). See OpenSearch time units reference.
Settings JSON object containing configuration options for the index, such as number of shards and replicas. See OpenSearch index settings documentation.
Timeout Time period to wait for a response before the request fails. Default is "30s" (thirty seconds). See OpenSearch time units reference.
Wait for Active Shards Number or keyword ("all") specifying how many shard copies must be active before proceeding. Default is "1" (primary shard only).

Output

The output JSON contains the response from the OpenSearch API after attempting to create the index. It typically includes confirmation details such as acknowledgment status and any metadata returned by OpenSearch about the created index.

Example output structure:

{
  "id": "indexId",
  "acknowledged": true,
  "shards_acknowledged": true,
  "index": "indexId"
}

If the creation is successful, the output confirms the index was created. If there is an error, it will be surfaced accordingly.

Dependencies

  • Requires an active OpenSearch cluster accessible via network.
  • Needs an API authentication token or key configured in n8n credentials to authorize requests to the OpenSearch API.
  • Uses internal helper functions to make HTTP requests to OpenSearch endpoints.

Troubleshooting

  • Common issues:

    • Invalid JSON syntax in aliases, mappings, or settings fields can cause request failures.
    • Insufficient permissions or incorrect API credentials will result in authorization errors.
    • Specifying an index name that already exists will cause a conflict error.
    • Timeout values too low may cause premature request failures if the cluster is slow to respond.
  • Error messages:

    • Errors returned from OpenSearch include a type and reason. For example, resource_already_exists_exception indicates the index already exists.
    • Network errors or timeouts indicate connectivity issues or misconfigured timeout properties.
  • Resolutions:

    • Validate JSON inputs carefully using external tools before pasting.
    • Ensure API credentials have sufficient privileges.
    • Use unique index names or delete existing indices before creating new ones.
    • Adjust timeout and master timeout values based on cluster responsiveness.

Links and References

Discussion