query

package
v8.17.0 Latest Latest
Warning

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

Go to latest
Published: Dec 17, 2024 License: Apache-2.0 Imports: 13 Imported by: 2

Documentation

Overview

Run an ES|QL query. Get search results for an ES|QL (Elasticsearch query language) query.

Index

Constants

This section is empty.

Variables

View Source
var ErrBuildPath = errors.New("cannot build path, check for missing path parameters")

ErrBuildPath is returned in case of missing parameters within the build of the request.

Functions

func Helper added in v8.14.0

func Helper[T any](ctx context.Context, esqlQuery *Query) ([]T, error)

Helper takes a generic type T, a context.Context and an esql.Query request. Returns an array of T using the json.Unmarshaler of the type.

Types

type EsqlIterator added in v8.14.0

type EsqlIterator[T any] interface {
	Next() (*T, error)
	More() bool
}

func NewIteratorHelper added in v8.14.0

func NewIteratorHelper[T any](ctx context.Context, query *Query) (EsqlIterator[T], error)

Helper takes a generic type T, a context.Context and an esql.Query request buffer the response and provides an API to consume one item at a time.

type NewQuery

type NewQuery func() *Query

NewQuery type alias for index.

func NewQueryFunc

func NewQueryFunc(tp elastictransport.Interface) NewQuery

NewQueryFunc returns a new instance of Query with the provided transport. Used in the index of the library this allows to retrieve every apis in once place.

type Query

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

func New

Run an ES|QL query. Get search results for an ES|QL (Elasticsearch query language) query.

https://www.elastic.co/guide/en/elasticsearch/reference/current/esql-rest.html

func (*Query) Columnar

func (r *Query) Columnar(columnar bool) *Query

Columnar By default, ES|QL returns results as rows. For example, FROM returns each individual document as one row. For the JSON, YAML, CBOR and smile formats, ES|QL can return the results in a columnar fashion where one row represents all the values of a certain column in the results. API name: columnar

func (*Query) Delimiter

func (r *Query) Delimiter(delimiter string) *Query

Delimiter The character to use between values within a CSV row. Only valid for the CSV format. API name: delimiter

func (Query) Do

func (r Query) Do(providedCtx context.Context) (Response, error)

Do runs the request through the transport, handle the response and returns a query.Response

func (*Query) DropNullColumns added in v8.16.0

func (r *Query) DropNullColumns(dropnullcolumns bool) *Query

DropNullColumns Should columns that are entirely `null` be removed from the `columns` and `values` portion of the results? Defaults to `false`. If `true` then the response will include an extra section under the name `all_columns` which has the name of all columns. API name: drop_null_columns

func (*Query) ErrorTrace added in v8.14.0

func (r *Query) ErrorTrace(errortrace bool) *Query

ErrorTrace When set to `true` Elasticsearch will include the full stack trace of errors when they occur. API name: error_trace

func (*Query) Filter

func (r *Query) Filter(filter *types.Query) *Query

Filter Specify a Query DSL query in the filter parameter to filter the set of documents that an ES|QL query runs on. API name: filter

func (*Query) FilterPath added in v8.14.0

func (r *Query) FilterPath(filterpaths ...string) *Query

FilterPath Comma-separated list of filters in dot notation which reduce the response returned by Elasticsearch. API name: filter_path

func (*Query) Format

func (r *Query) Format(format esqlformat.EsqlFormat) *Query

Format A short version of the Accept header, e.g. json, yaml. API name: format

func (*Query) Header

func (r *Query) Header(key, value string) *Query

Header set a key, value pair in the Query headers map.

func (*Query) HttpRequest

func (r *Query) HttpRequest(ctx context.Context) (*http.Request, error)

HttpRequest returns the http.Request object built from the given parameters.

func (*Query) Human added in v8.14.0

func (r *Query) Human(human bool) *Query

Human When set to `true` will return statistics in a format suitable for humans. For example `"exists_time": "1h"` for humans and `"eixsts_time_in_millis": 3600000` for computers. When disabled the human readable values will be omitted. This makes sense for responses being consumed only by machines. API name: human

func (*Query) Locale

func (r *Query) Locale(locale string) *Query

API name: locale

func (*Query) Params

func (r *Query) Params(params ...types.FieldValue) *Query

Params To avoid any attempts of hacking or code injection, extract the values in a separate list of parameters. Use question mark placeholders (?) in the query string for each of the parameters. API name: params

func (Query) Perform

func (r Query) Perform(providedCtx context.Context) (*http.Response, error)

Perform runs the http.Request through the provided transport and returns an http.Response.

func (*Query) Pretty added in v8.14.0

func (r *Query) Pretty(pretty bool) *Query

Pretty If set to `true` the returned JSON will be "pretty-formatted". Only use this option for debugging only. API name: pretty

func (*Query) Profile added in v8.16.0

func (r *Query) Profile(profile bool) *Query

Profile If provided and `true` the response will include an extra `profile` object with information on how the query was executed. This information is for human debugging and its format can change at any time but it can give some insight into the performance of each part of the query. API name: profile

func (*Query) Query

func (r *Query) Query(query string) *Query

Query The ES|QL query API accepts an ES|QL query string in the query parameter, runs it, and returns the results. API name: query

func (*Query) Raw

func (r *Query) Raw(raw io.Reader) *Query

Raw takes a json payload as input which is then passed to the http.Request If specified Raw takes precedence on Request method.

func (*Query) Request

func (r *Query) Request(req *Request) *Query

Request allows to set the request property with the appropriate payload.

func (*Query) Tables added in v8.16.0

func (r *Query) Tables(tables map[string]map[string]types.TableValuesContainer) *Query

Tables Tables to use with the LOOKUP operation. The top level key is the table name and the next level key is the column name. API name: tables

type Request

type Request struct {

	// Columnar By default, ES|QL returns results as rows. For example, FROM returns each
	// individual document as one row. For the JSON, YAML, CBOR and smile formats,
	// ES|QL can return the results in a columnar fashion where one row represents
	// all the values of a certain column in the results.
	Columnar *bool `json:"columnar,omitempty"`
	// Filter Specify a Query DSL query in the filter parameter to filter the set of
	// documents that an ES|QL query runs on.
	Filter *types.Query `json:"filter,omitempty"`
	Locale *string      `json:"locale,omitempty"`
	// Params To avoid any attempts of hacking or code injection, extract the values in a
	// separate list of parameters. Use question mark placeholders (?) in the query
	// string for each of the parameters.
	Params []types.FieldValue `json:"params,omitempty"`
	// Profile If provided and `true` the response will include an extra `profile` object
	// with information on how the query was executed. This information is for human
	// debugging
	// and its format can change at any time but it can give some insight into the
	// performance
	// of each part of the query.
	Profile *bool `json:"profile,omitempty"`
	// Query The ES|QL query API accepts an ES|QL query string in the query parameter,
	// runs it, and returns the results.
	Query string `json:"query"`
	// Tables Tables to use with the LOOKUP operation. The top level key is the table
	// name and the next level key is the column name.
	Tables map[string]map[string]types.TableValuesContainer `json:"tables,omitempty"`
}

Request holds the request body struct for the package query

https://github.com/elastic/elasticsearch-specification/blob/2f823ff6fcaa7f3f0f9b990dc90512d8901e5d64/specification/esql/query/QueryRequest.ts#L26-L91

func NewRequest

func NewRequest() *Request

NewRequest returns a Request

func (*Request) FromJSON

func (r *Request) FromJSON(data string) (*Request, error)

FromJSON allows to load an arbitrary json into the request structure

type Response

type Response = []byte

func NewResponse

func NewResponse() Response

NewResponse returns a Response

Jump to

Keyboard shortcuts

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