camel-component-opensearch
OpenSearch component for rust-camel integration framework
Overview
The OpenSearch component provides comprehensive OpenSearch integration for rust-camel, supporting 7 core operations for document indexing, search, and management. It enables producer mode for executing OpenSearch operations.
Features
- 7 Core Operations: INDEX, SEARCH, GET, DELETE, UPDATE, BULK, MULTIGET
- Producer Mode: Execute OpenSearch operations and receive responses
- Connection Options: Host, port, username, password, TLS support
- Async Native: Built on
tokioand async HTTP client - Global Configuration: Configure defaults via Camel.toml
Installation
Add to your Cargo.toml:
[]
= "*"
URI Format
opensearch://host:port/index?options
opensearchs://host:port/index?options (TLS enabled)
URI Options
| Option | Default | Description |
|---|---|---|
operation |
SEARCH |
OpenSearch operation to perform |
username |
- | Username for authentication |
password |
- | Password for authentication |
Supported Operations
| Operation | Description |
|---|---|
INDEX |
Index a document (create or replace) |
SEARCH |
Search documents using query |
GET |
Retrieve a document by ID |
DELETE |
Delete a document by ID |
UPDATE |
Update a document (partial update) |
BULK |
Bulk operations for multiple documents |
MULTIGET |
Retrieve multiple documents by IDs |
Usage
Index a Document
use RouteBuilder;
use OpenSearchComponent;
let mut ctx = new;
ctx.register_component;
// INDEX: Store a document
let index_route = from
.set_header
.set_body
.to
.build?;
Search Documents
// SEARCH: Query documents
let search_route = from
.set_body
.to
.build?;
Get a Document
// GET: Retrieve by ID
let get_route = from
.set_header
.to
.build?;
Delete a Document
// DELETE: Remove by ID
let delete_route = from
.set_header
.to
.build?;
Update a Document
// UPDATE: Partial update
let update_route = from
.set_header
.set_body
.to
.build?;
Bulk Operations
// BULK: Multiple operations (body is a JSON array of action+doc pairs)
let bulk_route = from
.set_body
.to
.build?;
Multi-Get
// MULTIGET: Retrieve multiple documents
let multiget_route = from
.set_body
.to
.build?;
With Authentication
let auth_route = from
.to
.build?;
With TLS
// Use opensearchs:// for HTTPS
let tls_route = from
.to
.build?;
Exchange Headers
| Header | Direction | Description |
|---|---|---|
CamelOpenSearch.Id |
Input | Document ID (for INDEX, GET, DELETE, UPDATE) |
CamelOpenSearch.Operation |
Input | Operation to perform (overrides URI operation) |
Example: Document Indexing Pipeline
use RouteBuilder;
use OpenSearchComponent;
use CamelContext;
async
Example: Search and Process
// Search and process results
let route = from
.set_body
.to
.process
.build?;
Global Configuration
Configure default OpenSearch connection settings in Camel.toml that apply to all OpenSearch endpoints:
[]
= "localhost" # OpenSearch host (default: localhost)
= 9200 # OpenSearch port (default: 9200)
= "admin" # Optional: default username
= "secret" # Optional: default password
= "SEARCH" # Optional: default operation
= "default" # Optional: default index name
URI parameters always override global defaults:
// Uses global host/port (localhost:9200)
.to
// Overrides port from global config
.to
// Full override with different host
.to
// Override username/password from global config
.to
Profile-Specific Configuration
[]
= "localhost"
= 9200
[]
= "opensearch-prod.internal"
= 9200
= "app-user"
= "${OPENSEARCH_PASSWORD}"
Documentation
License
Apache-2.0
Contributing
Contributions are welcome! Please see the main repository for details.