SearchFn
ReferenceAdapters

Elasticsearch / OpenSearch Adapter

Elastic-compatible adapter for Elasticsearch and OpenSearch clusters.

A single adapter implementation that supports both Elasticsearch and OpenSearch. Select your engine at construction time.

When to Use

  • Large-scale search with millions of documents
  • Advanced relevance tuning with field boosts and custom analyzers
  • Existing Elasticsearch or OpenSearch infrastructure

Installation

npm install @searchfn/adapters

Usage

Elasticsearch

import { ElasticsearchAdapter } from "@searchfn/adapters";

const adapter = new ElasticsearchAdapter({
  node: "https://es.example.com:9200",
  engine: "elasticsearch",
  auth: { apiKey: process.env.ES_API_KEY! },
  indexPrefix: "myapp",
});

await adapter.initialize({
  resources: [{ name: "tasks", searchFields: ["title", "description"] }],
});

const ids = await adapter.search({ resource: "tasks", query: "docs" });

OpenSearch

import { OpenSearchAdapter } from "@searchfn/adapters";

const adapter = new OpenSearchAdapter({
  node: "https://opensearch.example.com:9200",
  auth: { username: "admin", password: process.env.OS_PASSWORD! },
  indexPrefix: "myapp",
});

OpenSearchAdapter is a convenience wrapper that sets engine: "opensearch" automatically.

Configuration

OptionTypeDefaultDescription
nodestringRequired. Cluster endpoint URL.
engine"elasticsearch" | "opensearch""elasticsearch"Select the engine dialect.
auth{ username, password } | { apiKey }Cluster authentication credentials.
indexPrefixstring"searchfn"Prefix for index names ({prefix}-{resource}).
requestTimeoutMsnumber30000Request timeout.
retry.maxRetriesnumber2Retry attempts for transient failures.
retry.baseDelayMsnumber100Base delay between retries.
retry.maxDelayMsnumber5000Maximum delay between retries.
loggerAdapterLoggerOptional adapter-level logger.

Capabilities

CapabilitySupported
persistentYes
searchAllYes
fuzzyYes
fieldBoostsYes

Behavior

  • Single implementation handles both Elasticsearch and OpenSearch with dialect-aware query generation.
  • Index lifecycle (create, delete) is deterministic and idempotent.
  • Results are ordered by score with deterministic tie-breaking.
  • Unsupported engine values return DFQL_UNSUPPORTED.
  • Keep auth credentials in secure runtime secrets — never hardcode them.