GitHunt
SD

sdqri/effdsl

Elasticsearch query builder for golang

effdsl

GitHub Release
GoDoc
Go Report Card
GitHub License
Contributions welcome
Mentioned in Awesome Go

effdsl is a composable Go DSL for building Elasticsearch queries and aggregations with type-safe options and predictable JSON output.

Key Features

  • Type-safe query construction without raw JSON maps
  • Functional options API for readable, composable queries
  • Broad aggregation coverage (metrics, bucket, pipeline)

For details and examples, see the documentation.

Getting started

Install

With Go module support, add the import and Go will fetch dependencies automatically:

import "github.com/sdqri/effdsl/v2"

Or install directly:

go get -u github.com/sdqri/effdsl/v2

How to use

Start with effdsl.Define() and compose queries with options.

Examples

Raw JSON example

Example match query using a raw JSON string:

import (
    es "github.com/elastic/go-elasticsearch/v8"
)

query := `{
  "query": {
    "match": {
      "message": {
        "query": "Hello World"
      }
    }
  }
}`

res, err := es.Search(
  es.Search.WithBody(strings.NewReader(query)),
)

Using effdsl

The same query using effdsl:

import (
    es "github.com/elastic/go-elasticsearch/v8"
    
    "github.com/sdqri/effdsl/v2"
    mq "github.com/sdqri/effdsl/v2/queries/matchquery"
)

query, err := effdsl.Define(
    effdsl.WithQuery(
        mq.MatchQuery("message", "Hello World"),
    ),
)

res, err := es.Search(
  es.Search.WithBody(strings.NewReader(query)),
)

For more examples and details on query parameters, visit the documentation.

Contributing

Contributions are welcome. Thanks for helping improve effdsl. ๐Ÿค Please see CONTRIBUTING.md to get started.

License

This project is licensed under the MIT License. See LICENSE.md.

Languages

Go100.0%

Contributors

MIT License
Created January 22, 2023
Updated February 12, 2026
sdqri/effdsl | GitHunt