effdsl is a composable Go DSL for building Elasticsearch queries and aggregations with type-safe options and predictable JSON output.
- 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.
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/v2Start with effdsl.Define() and compose queries with options.
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.
Contributions are welcome. Thanks for helping improve effdsl. 🤝 Please see CONTRIBUTING.md to get started.
This project is licensed under the MIT License. See LICENSE.md.