Skip to content
Closed
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
53 changes: 53 additions & 0 deletions docs/examples/connectors/elasticsearch/elasticsearch.vjs.example
Original file line number Diff line number Diff line change
@@ -0,0 +1,53 @@
# connector: elasticsearch — Comprehensive Elasticsearch search engine integration
#
# Platform connector for Elasticsearch. Supports multiple operations:
# - Document operations (index, get, update, delete, bulk)
# - Search operations (search with query DSL, multi-search)
# - Index management (create index, delete index, update mappings)
# - Aggregations (terms, stats, date histogram, etc.)
# - Cluster operations (health, stats, nodes info)
#
# Uses exec-rpc driver wrapping an Elasticsearch client process. The process accepts
# JSON requests on stdin and returns JSON responses on stdout.
#
# Subjects:
# REQUEST: vxrpc.elasticsearch (outside vx.* namespace for request/reply)
#
# Secrets:
# elasticsearch/url - Elasticsearch cluster URL (http://localhost:9200 or https://...)
# elasticsearch/username - Elasticsearch username (optional, for auth)
# elasticsearch/password - Elasticsearch password (optional, for auth)
# elasticsearch/api_key - Elasticsearch API key (optional, alternative to username/password)
#
# Rate limits: Depends on cluster configuration and resources
# Connection pooling: Managed by the exec process
#
# Request format (JSON on stdin):
# {"op":"index","index":"users","id":"123","document":{"name":"John","email":"john@example.com"}}
# {"op":"search","index":"users","query":{"match":{"name":"John"}}}
# {"op":"bulk","operations":[{"index":{"_index":"users","_id":"1"}},{"name":"John"},{"index":{"_index":"users","_id":"2"}},{"name":"Jane"}]}
# {"op":"aggregate","index":"orders","aggs":{"total_sales":{"sum":{"field":"amount"}}}}
#
# Response format (JSON on stdout):
# {"ok":true,"_id":"123","_index":"users","_version":1,"result":"created"}
# {"ok":true,"hits":{"total":{"value":1},"hits":[{"_source":{"name":"John"}}]}}
# {"ok":false,"error":"index_not_found_exception"}
#
# Note: This connector requires an Elasticsearch client wrapper binary (e.g., vejas-elasticsearch)
# that implements the exec-rpc protocol. The binary would use an Elasticsearch driver
# (e.g., elasticsearch crate in Rust) to execute operations.

driver "exec-rpc"

# Request/reply subject (outside vx.* namespace)
REQUEST_SUBJECT = "vxrpc.elasticsearch"

# Elasticsearch client wrapper command
CMD = "/opt/vejas/vejas-elasticsearch"

# Environment variables for connection
ENV = {
ELASTICSEARCH_URL: secret("elasticsearch/url"),
ELASTICSEARCH_USERNAME: secret("elasticsearch/username"),
ELASTICSEARCH_PASSWORD: secret("elasticsearch/password")
}
46 changes: 46 additions & 0 deletions docs/examples/connectors/elasticsearch/fixture.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,46 @@
{
"ok": true,
"took": 5,
"timed_out": false,
"_shards": {
"total": 1,
"successful": 1,
"skipped": 0,
"failed": 0
},
"hits": {
"total": {
"value": 2,
"relation": "eq"
},
"max_score": 1.0,
"hits": [
{
"_index": "users",
"_id": "1",
"_score": 1.0,
"_source": {
"name": "John Doe",
"email": "john.doe@example.com",
"age": 32,
"role": "admin",
"active": true,
"created_at": "2023-11-23T12:00:00.000Z"
}
},
{
"_index": "users",
"_id": "2",
"_score": 0.8,
"_source": {
"name": "Jane Smith",
"email": "jane.smith@example.com",
"age": 28,
"role": "user",
"active": true,
"created_at": "2023-11-23T11:30:00.000Z"
}
}
]
}
}
151 changes: 151 additions & 0 deletions docs/examples/connectors/elasticsearch/mock.mjs
Original file line number Diff line number Diff line change
@@ -0,0 +1,151 @@
#!/usr/bin/env node
// Mock Elasticsearch exec-rpc wrapper for admission testing
// Simulates vejas-elasticsearch binary that accepts JSON requests on stdin

import readline from 'readline';

const users = [
{
_index: 'users',
_id: '1',
_score: 1.0,
_source: {
name: 'John Doe',
email: 'john.doe@example.com',
age: 32,
role: 'admin',
active: true,
created_at: '2023-11-23T12:00:00.000Z'
}
},
{
_index: 'users',
_id: '2',
_score: 0.8,
_source: {
name: 'Jane Smith',
email: 'jane.smith@example.com',
age: 28,
role: 'user',
active: true,
created_at: '2023-11-23T11:30:00.000Z'
}
}
];

const rl = readline.createInterface({
input: process.stdin,
output: process.stdout,
terminal: false
});

rl.on('line', (line) => {
try {
const request = JSON.parse(line);

if (request.op === 'search') {
// Search documents
const response = {
ok: true,
took: 5,
timed_out: false,
_shards: {
total: 1,
successful: 1,
skipped: 0,
failed: 0
},
hits: {
total: {
value: users.length,
relation: 'eq'
},
max_score: 1.0,
hits: users
}
};
console.log(JSON.stringify(response));
} else if (request.op === 'index') {
// Index a document
const response = {
ok: true,
_index: request.index,
_id: request.id || Date.now().toString(),
_version: 1,
result: 'created'
};
console.log(JSON.stringify(response));
} else if (request.op === 'get') {
// Get a document
const response = {
ok: true,
_index: request.index,
_id: request.id,
_version: 1,
found: true,
_source: users[0]._source
};
console.log(JSON.stringify(response));
} else if (request.op === 'update') {
// Update a document
const response = {
ok: true,
_index: request.index,
_id: request.id,
_version: 2,
result: 'updated'
};
console.log(JSON.stringify(response));
} else if (request.op === 'delete') {
// Delete a document
const response = {
ok: true,
_index: request.index,
_id: request.id,
_version: 1,
result: 'deleted'
};
console.log(JSON.stringify(response));
} else if (request.op === 'bulk') {
// Bulk operations
const response = {
ok: true,
took: 10,
errors: false,
items: [
{ index: { _index: 'users', _id: '1', _version: 1, result: 'created', status: 201 } },
{ index: { _index: 'users', _id: '2', _version: 1, result: 'created', status: 201 } }
]
};
console.log(JSON.stringify(response));
} else if (request.op === 'aggregate') {
// Aggregations
const response = {
ok: true,
took: 5,
hits: {
total: { value: 2 },
hits: []
},
aggregations: {
total_sales: {
value: 1500.50
}
}
};
console.log(JSON.stringify(response));
} else {
console.log(JSON.stringify({
ok: false,
error: `Unknown operation: ${request.op}`
}));
}
} catch (err) {
console.log(JSON.stringify({
ok: false,
error: err.message
}));
}
});

console.error('Mock Elasticsearch connector started');
3 changes: 3 additions & 0 deletions docs/examples/connectors/elasticsearch/overrides.json
Original file line number Diff line number Diff line change
@@ -0,0 +1,3 @@
{
"CMD": "node mock.mjs"
}
Loading