elasticutil

package module
v0.7.0 Latest Latest
Warning

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

Go to latest
Published: Jan 5, 2026 License: BSD-3-Clause Imports: 7 Imported by: 0

README

ElasticUtil

A Golang library that assists in the use of Elasticsearch

Table of Contents

1. Description

ElasticUtil is a generic library that assists in the use of Elasticsearch, using olivere/elastic library and the offical library. It is possible to create elastic's queries using only one struct. It is also possible to translate errors and responses.

2. Technology Stack

Stack Version
Golang v1.21.3
golangci-lint v1.54.2

3. Getting Started

  • Prerequisites
    • Any Golang programming language version installed, preferred 1.18 or later.
  • Install
    go get -u github.com/arquivei/elasticutil
    
  • Configuration Setup
    go mod vendor
    go mod tidy
    
  • Examples

5. Collaborators

6. Contributing

Please read CONTRIBUTING.md for details on our code of conduct, and the process for submitting pull requests to us.

7. Versioning

We use Semantic Versioning for versioning. For the versions available, see the tags on this repository.

8. License

This project is licensed under the BSD 3-Clause - see the LICENSE.md file for details.

8. Contact Information

All contact may be doing by marcos.filho@arquivei.com.br

Documentation

Index

Constants

This section is empty.

Variables

View Source
var ErrNotAllShardsReplied = errors.New("not all shards replied")

ErrNotAllShardsReplied is returned when no all elasticsearch's shards successfully reply.

Functions

func AllShardsMustReplyOnElasticSearch

func AllShardsMustReplyOnElasticSearch(
	results *elastic.SearchResult,
	err error,
) (*elastic.SearchResult, error)

AllShardsMustReplyOnElasticSearch checks if any shard failed to respond.

func BuildElasticBoolQuery

func BuildElasticBoolQuery(
	ctx context.Context,
	filter Filter,
) (elastic.Query, error)

BuildElasticBoolQuery builds a olivere/elastic's query based on Filter.

func GetElasticPaginatorFromHits

func GetElasticPaginatorFromHits(hits []*elastic.SearchHit) (string, error)

GetElasticPaginatorFromHits gets the elastic sort in the last hit as a json string.

func GetErrorFromElasticResponse

func GetErrorFromElasticResponse(err error) error

GetErrorFromElasticResponse checks if err is an *elastic.Error and returns an error with a formatted message. nolint: gocritic, errorlint

func MarshalQuery

func MarshalQuery(query elastic.Query) string

MarshalQuery transforms a olivere/elastic's query in a string for log and test purpose.

Types

type CustomQuery added in v0.1.11

type CustomQuery func() (*elastic.BoolQuery, error)

CustomQuery is the type function that will return the custom query.

type CustomSearch added in v0.1.11

type CustomSearch struct {
	GetQuery CustomQuery
}

CustomSearch is the struct that contains the CustomQuery function.

func NewCustomSearch added in v0.1.11

func NewCustomSearch(query CustomQuery) CustomSearch

NewCustomSearch creates a CustomSearch struct with the given CustomQuery function.

type Filter

type Filter struct {
	Must    interface{}
	MustNot interface{}
	Exists  interface{}
}

Filter is a struct that eill be transformed in a olivere/elastic's query.

"Must" and "MustNot" is for the terms, range and multi match query. "Exists" is for the exists query. For nested queries, uses the Nested type.

type FloatRange

type FloatRange struct {
	From float64
	To   float64
}

FloatRange represents a float range with a beginning and an end.

type FullTextSearchMust

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

FullTextSearchMust Represents a Must's Full Text Search.

func NewFullTextSearchMust

func NewFullTextSearchMust(payload interface{}) FullTextSearchMust

NewFullTextSearchMust creates a FullTextSearchMust struct with the given payload.

type FullTextSearchShould

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

FullTextSearchMust Represents a Should's Full Text Search.

func NewFullTextSearchShould

func NewFullTextSearchShould(payload interface{}) FullTextSearchShould

NewFullTextSearchShould creates a FullTextSearchShould struct with the given payload.

type IntRange

type IntRange struct {
	From uint64
	To   uint64
}

IntRange represents an int range with a beginning and an end.

type MultiMatchSearchShould added in v0.2.0

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

MultiMatchSearchShould Represents a Should's Multi Match Search.

func NewMultiMatchSearchShould added in v0.2.0

func NewMultiMatchSearchShould(payload interface{}) MultiMatchSearchShould

NewMultiMatchSearchShould creates a MultiMatchSearchShould struct with the given payload.

type Nested

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

Nested represents a nested query.

func NewNested

func NewNested(payload interface{}) Nested

NewNested creates a Nested struct with the given payload.

type Ranges

type Ranges interface {
	time.Time | uint64 | float64
}

type TimeRange

type TimeRange struct {
	From time.Time
	To   time.Time
}

TimeRange represents a time range with a beginning and an end.

Directories

Path Synopsis
examples
official command
olivere command
official
v7

Jump to

Keyboard shortcuts

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