Ricky Moony and Lucy, a moon shaped mascot for Dream with the star shaped mascot for Gleam, each with cute cartoon eyes and a smile

Simple OpenSearch client for Gleam


Hex Package Latest Release HexDocs Coverage MIT License 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

Installation

gleam add dream_opensearch

Quick Start

Index, search and delete a document Tested snippet Guide: Getting started

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

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 ❤️