Skip to content

sdqri/effdsl

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

84 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

effdsl

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

Getting started

Getting effdsl

With Go module 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:

$ 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:

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:

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.

🤝 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 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.)