esquery/common.go
Ido Perlmuter 8e5dea816b
Add Search() function, two new aggregations (#7)
This commit implements a Search() function, which allow for running
search requests with both a query and aggregations. This function is
meant to more accurately implement the structure of search requests
accepted by ElasticSearch's Search API.

The Query() and Aggregate() functions are still included by the library,
but now simply call Search() internally, making them simple shortcuts.

Two new aggregations are also added: "terms" and "top_hits". These are
implemented a bit differently than previously implemented ones. The
structs and methods for ElasticSearch queries and aggregations will
eventually be auto-generated from a specification file, and will look
more like the new implementations of these new aggregations.
2020-04-06 12:03:42 +03:00

29 lines
711 B
Go

package esquery
// Source represents the "_source" option which is commonly accepted in ES
// queries. Currently, only the "includes" option is supported.
type Source struct {
includes []string
}
// Map returns a map representation of the Source object.
func (source Source) Map() map[string]interface{} {
return map[string]interface{}{
"includes": source.includes,
}
}
// Sort represents a list of keys to sort by.
type Sort []map[string]interface{}
// Order is the ordering for a sort key (ascending, descending).
type Order string
const (
// OrderAsc represents sorting in ascending order.
OrderAsc Order = "asc"
// OrderDesc represents sorting in descending order.
OrderDesc Order = "desc"
)