This commit performs the following modifications: - The library is properly documented in Godoc format. - The CustomQuery function is made to be a bit more versatile by allowing it to also be used standalone (i.e. instead of passing a `CustomQuery` as a parameter to the `Query` function, they now have their own `Run` method). - Queries and aggregations can now also be executed using the `RunSearch` method. This method is the same as the `Run` method, except that instead of an `*elasticSearch.Client` value, it accepts an `esapi.Search` value. This is provided for consuming code that needs to implement mock clients of ElasticSearch (e.g. for test purposes). The ElasticSearch client does not provide an interface type describing its API, so its Search function (which is actually a field of a function type) can be used instead. - Bugfix: the CustomAgg function was unusable as it did not accept a name parameter and thus did not implement the Aggregation interface. - Bugfix: the enumeration types are rewritten according to Go standards, and the `RangeRelation` type's default value is now empty. - The golint and godox linters are added.
48 lines
1.3 KiB
Go
48 lines
1.3 KiB
Go
package esquery
|
|
|
|
// BoostingQuery represents a compound query of type "boosting", as described in
|
|
// https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-boosting-query.html
|
|
type BoostingQuery struct {
|
|
// Pos is the positive part of the query.
|
|
Pos Mappable
|
|
// Neg is the negative part of the query.
|
|
Neg Mappable
|
|
// NegBoost is the negative boost value.
|
|
NegBoost float32
|
|
}
|
|
|
|
// Boosting creates a new compound query of type "boosting".
|
|
func Boosting() *BoostingQuery {
|
|
return &BoostingQuery{}
|
|
}
|
|
|
|
// Positive sets the positive part of the boosting query.
|
|
func (q *BoostingQuery) Positive(p Mappable) *BoostingQuery {
|
|
q.Pos = p
|
|
return q
|
|
}
|
|
|
|
// Negative sets the negative part of the boosting query.
|
|
func (q *BoostingQuery) Negative(p Mappable) *BoostingQuery {
|
|
q.Neg = p
|
|
return q
|
|
}
|
|
|
|
// NegativeBoost sets the negative boost value.
|
|
func (q *BoostingQuery) NegativeBoost(b float32) *BoostingQuery {
|
|
q.NegBoost = b
|
|
return q
|
|
}
|
|
|
|
// Map returns a map representation of the boosting query, thus implementing
|
|
// the Mappable interface.
|
|
func (q *BoostingQuery) Map() map[string]interface{} {
|
|
return map[string]interface{}{
|
|
"boosting": map[string]interface{}{
|
|
"positive": q.Pos.Map(),
|
|
"negative": q.Neg.Map(),
|
|
"negative_boost": q.NegBoost,
|
|
},
|
|
}
|
|
}
|