elastic

package module
v0.0.0-...-a68e130 Latest Latest
Warning

This package is not in the latest version of its module.

Go to latest
Published: Mar 7, 2025 License: MIT Imports: 7 Imported by: 0

Documentation

Index

Constants

This section is empty.

Variables

This section is empty.

Functions

This section is empty.

Types

type Option

type Option func(*QueryGenerator)

Option is a function that configures a query generator.

func WithFieldMapper

func WithFieldMapper(fieldMapper func(name string) (string, error)) Option

WithFieldMapper allows validating incoming field names, and mapping them to internally defined ones. This can be used to prevent users from requiring knowledge about implementation details. Example usage:

WithFieldMapper(func(name string) (string, error) {
	if !allowedFields[name] {
		return "", fmt.Errorf("field %s is not allowed", name)
	}
	if name == "release_time" {
		return "time", nil
	}
	return name, nil
})

func WithFieldValueMapper

func WithFieldValueMapper(fieldValueMapper func(name, value string) (string, error)) Option

WithFieldValueMapper allows mapping incoming values for a field, or returning an error on invalid values. Example usage:

WithFieldValueMapper(func(name, value string) (string, error) {
	if name == "user_id" and !isValidUserID(value) {
		return "", fmt.Errorf("user id %s is not allowed", value)
	}
	return fmt.Sprintf("uid_%s", value), nil
})

type QueryGenerator

type QueryGenerator struct {
	// contains filtered or unexported fields
}

func NewQueryGenerator

func NewQueryGenerator(options ...Option) *QueryGenerator

func (*QueryGenerator) ConvertAST

func (q *QueryGenerator) ConvertAST(root kqlfilter.Node) (types.Query, error)

ConvertAST converts a KQL AST to an Elasticsearch query.

Jump to

Keyboard shortcuts

? : This menu
/ : Search site
f or F : Jump to
y or Y : Canonical URL