https://github.com/sdqri/effdsl
Elasticsearch query builder for golang
https://github.com/sdqri/effdsl
elasticsearch golang orm query-builder querydsl
Last synced: about 2 months ago
JSON representation
Elasticsearch query builder for golang
- Host: GitHub
- URL: https://github.com/sdqri/effdsl
- Owner: sdqri
- License: mit
- Created: 2023-01-22T14:36:02.000Z (almost 3 years ago)
- Default Branch: master
- Last Pushed: 2024-12-16T08:42:18.000Z (11 months ago)
- Last Synced: 2024-12-16T09:32:36.609Z (11 months ago)
- Topics: elasticsearch, golang, orm, query-builder, querydsl
- Language: Go
- Homepage: https://sdqri.github.io/effdsl/
- Size: 824 KB
- Stars: 27
- Watchers: 4
- Forks: 3
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- Contributing: CONTRIBUTING.md
- License: LICENSE
- Code of conduct: CODE_OF_CONDUCT.md
- Security: SECURITY.md
Awesome Lists containing this project
- awesome-go - sdqri/effdsl
- awesome-go - sdqri/effdsl
- trackawesomelist - effdsl (β24) - Elasticsearch query builder for Go. (Recently Updated / [Sep 15, 2024](/content/2024/09/15/README.md))
README
# effdsl

[](https://pkg.go.dev/github.com/sdqri/effdsl/v2?tab=doc)
[](https://goreportcard.com/report/github.com/sdqri/effdsl)

[](https://github.com/avelino/awesome-go)
This module provides a simple and functional way to build Elasticsearch queries in Go.
### π Key Features
- **Type-safe query construction:** π‘οΈ Avoids error-prone maps and raw string literals by using intuitive function calls, enhancing type safety, auto-completion, and compile-time validation.
- **Procedural query creation:** β¨ Designed for straightforward and refined query building, particularly useful when queries need to be generated programmatically.
- **Comprehensive query support:** π Covers most compound, full-text, and term-level queries, with easy extension for additional types.
For more information, detailed guides, and examples, please read the [documentation](https://sdqri.github.io/effdsl).
## Getting started
### Getting effdsl
With [Go module](https://github.com/golang/go/wiki/Modules) support, simply add the following import
```
import "github.com/sdqri/effdsl/v2"
```
to your code, and then `go [build|run|test]` will automatically fetch the necessary dependencies.
Otherwise, run the following Go command to install the `effdsl` package:
```sh
$ go get -u github.com/sdqri/effdsl/v2
```
### How to use
Start with `effdsl.Define()`, and use types and documentations to find suitable options.
### π Examples:
**Traditional Way:**
Hereβs a simple match query in the traditional way using raw strings in Go:
```go
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:**
And hereβs the same query using effdsl:
```go
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](https://sdqri.github.io/effdsl).
## π€ Contribution
Contributions are welcome! Whether it's fixing a bug π, adding a new feature π, or improving the documentation π, your help is appreciated. Please check out the CONTRIBUTING.md guide to get started.
## π License
This project is licensed under the **MIT License**. For more details, see the [License](LICENSE.md) file. π ( **In short:** You can use, modify, and distribute this software freely as long as you include the original copyright notice and license. The software is provided "as-is" without warranties or guarantees.)