Awesome Go

effdsl

CategoryDatabase Drivers
SubcategorySearch and Analytic Databases
Stars0

Elasticsearch query builder for Go

About effdsl

effdsl

GitHub Release GoDoc Go Report Card GitHub License 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.

Frequently Asked Questions

What is effdsl?

effdsl is a Database Drivers library for the Go programming language. Elasticsearch query builder for Go

How do I install effdsl?

Install effdsl with the Go module system using `go get sdqri/effdsl`. Check the repository for the current installation instructions.

What category does effdsl belong to?

effdsl is listed under Database Drivers, specifically Search and Analytic Databases.

← Back to Search and Analytic Databases