Simple Node.js API to connect and search in OpenSearch.
npm installdocker-compose up -dnpm startFor development (with nodemon):
npm run devGET /search?query=term&index=index_name
Example:
curl "http://localhost:3000/search?query=test"GET /health
POST /document
Content-Type: application/json
{
"index": "documents",
"document": {
"title": "My document",
"content": "Document content",
"created_at": "2024-01-01"
}
}
GET /
Default settings are in the code, but you can use environment variables:
OPENSEARCH_URL: OpenSearch URL (default: https://localhost:9200)OPENSEARCH_USERNAME: Username (default: admin)OPENSEARCH_PASSWORD: Password (default: OpenSearch2024!Strong)PORT: API port (default: 3000)
# 1. Create a document
curl -X POST http://localhost:3000/document \
-H "Content-Type: application/json" \
-d '{
"index": "articles",
"document": {
"title": "Introduction to OpenSearch",
"content": "OpenSearch is a search and analytics tool...",
"author": "John Doe",
"date": "2024-01-15"
}
}'
# 2. Search documents
curl "http://localhost:3000/search?query=OpenSearch&index=articles"