Simple OpenSearch client for Gleam
dream_opensearch
A standalone HTTP client for OpenSearch (or Elasticsearch) clusters. It indexes, searches and deletes documents, and manages indices. It is built with the same quality standards as Dream, but it is completely independent. Use it in any Gleam project.
Features
- ✅ Document indexing and deletion
- ✅ Full-text search
- ✅ Index management
- ✅ Bulk operations
- ✅ Query builder helpers
- ✅ Typed errors: match on
Rejected,Unavailable,TimedOutand more - ✅ A client from a
dream_http_clientrequest, for a timeout, a recorder or a certificate authority - ✅ Zero dependencies on Dream or other frameworks
Installation
gleam add dream_opensearch
Quick Start
Index, search and delete a document

import dream_opensearch/client.{type Client, type OpenSearchError}
import dream_opensearch/document
import dream_opensearch/query
import gleam/json
// Create client
pub fn create_client() -> Result(Client, OpenSearchError) {
client.new("http://localhost:9200")
}
// Index a document
pub fn index_alice(opensearch: Client) -> Result(String, OpenSearchError) {
let user =
json.object([
#("name", json.string("Alice")),
#("email", json.string("alice@example.com")),
])
document.index(opensearch, "users", "123", json.to_string(user))
}
// Search documents
pub fn search_for_alice(opensearch: Client) -> Result(String, OpenSearchError) {
let search_query = query.match("name", "Alice")
document.search(opensearch, "users", search_query)
}
// Delete document
pub fn delete_alice(opensearch: Client) -> Result(String, OpenSearchError) {
document.delete(opensearch, "users", "123")
}
Guides
- Getting started: connect to a local or a secured cluster, then save, search for and delete documents from a Gleam module, with tests
- Searching an index: match, term, range and bool queries, pages and sorting, and reading the hits into your own types
- Loading documents in bulk: load many documents in one request, find the ones that failed, load in batches and retry
- Managing indexes: create an index with settings and a mapping, check, refresh, count, copy and delete indexes
- Handling errors: every error the client returns, the details of an OpenSearch error, what to retry, logs without the password, and the timeout
- Upgrading: the code changes from 3.x to 4.0.0, before and after
API Reference
The full API reference is on HexDocs. The guides show each function where a task needs it.
Design Principles
dream_opensearch follows Dream's design principles and contributing guide.
About Dream
This module was originally built for the Dream web toolkit, but it's completely standalone and can be used in any Gleam project. It follows Dream's design principles and will be maintained as part of the Dream ecosystem.
License
MIT — see LICENSE.md
Built in Gleam, on the BEAM, by the Dream Team ❤️