Skip to content

Add Elasticsearch Tools Plugin for Dify Platform #292

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
wants to merge 4 commits into
base: main
Choose a base branch
from

Conversation

stoplyy
Copy link
Contributor

@stoplyy stoplyy commented Apr 6, 2025

Description

This PR introduces the Elasticsearch Tools Plugin, a new plugin for the Dify platform that enables seamless interaction with Elasticsearch clusters. The plugin provides tools for managing Elasticsearch clusters, performing REST API calls, and executing various cluster operations.

Key Features:

  • Authentication: Supports username and password-based authentication for Elasticsearch clusters.
  • REST API Calls: Perform GET, POST, PUT, and DELETE operations on Elasticsearch clusters.
  • Cluster Operations:
    • Retrieve cluster health status.
    • Manage indices (mappings, settings, stats).
    • Execute search queries.
    • Perform custom REST API calls.
  • Flexible Configuration:
    • cluster_info: Map cluster names to their addresses.
    • auth_list: Map cluster names to their authentication credentials.

Files Added/Modified

Plugin Code:

  • provider/elasticsearch_tools.py: Implements the main provider logic for credential validation and cluster authentication.
  • tools/elasticsearch_rest.py: Implements the REST API tool logic for interacting with Elasticsearch clusters.
  • helper/auth_parser.py: Parses cluster and authentication information.
  • helper/elasticsearch_helper.py: Provides helper methods for Elasticsearch operations.

Plugin Configuration:

  • provider/elasticsearch_tools.yaml: Defines the plugin's metadata and credentials.
  • tools/elasticsearch_rest.yaml: Defines the REST API tool's parameters and outputs.

Documentation:

  • README.md: Provides an overview of the plugin, installation instructions, and usage examples.
  • PRIVACY.md: Details the plugin's data usage and privacy policy.

Assets:

  • _assets/icon.svg: Plugin icon representing Elasticsearch.

Installation Instructions

  1. Install dependencies:
    pip install -r requirements.txt
  2. Configure credentials in the platform:
    • cluster_info: JSON array mapping cluster names to addresses.
    • auth_list: JSON array mapping cluster names to authentication credentials.

Usage

Elasticsearch REST API Tool

  1. Perform a REST API call:
    • Specify cluster_name, endpoint, method, and body (if applicable).
    • Supports GET, POST, PUT, and DELETE methods.

Parameters:

  • cluster_name: The name of the Elasticsearch cluster to call (e.g., cluster_name_1).
  • endpoint: The API endpoint to call (e.g., _cluster/health).
  • method: The HTTP method to use (GET, POST, PUT, or DELETE).
  • body: The request body (optional, for POST and PUT methods).
  • timeout: The timeout for the request in seconds (default: 10).

Outputs:

  • success: Indicates whether the API call was successful.
  • error_message: Error message if the request failed.
  • result_object: The response as an object (if applicable).
  • result_array: The response as an array of objects (if applicable).
  • result_string: The response as a string (if applicable).

Testing

  • Unit tests are included to validate the functionality of the plugin components.
  • Mocking is used to simulate Elasticsearch cluster responses.

Privacy and Security

  • The plugin does not store or transmit user data outside the platform.
  • All data processing is performed temporarily during runtime.
  • Authentication credentials are securely managed by the platform.

Additional Notes

This plugin is designed to enhance the Dify platform by providing seamless integration with Elasticsearch clusters. It is a valuable addition for users who need to manage and interact with their Elasticsearch environments efficiently.

For more details, refer to the README.md file.


Checklist

  • Code follows the repository's coding standards.
  • Documentation is updated to reflect the new plugin.
  • Unit tests are included and pass successfully.
  • Plugin metadata and configuration files are validated.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

1 participant