Support Elasticsearch v8 #7
|
@ -35,7 +35,7 @@ This is an early release, API may still change.
|
|||
`esquery` is a Go module. To install, simply run this in your project's root directory:
|
||||
|
||||
```bash
|
||||
go get github.com/aquasecurity/esquery
|
||||
go get github.com/aquasecurity/esquery/v8
|
||||
```
|
||||
|
||||
## Usage
|
||||
|
@ -51,8 +51,8 @@ import (
|
|||
"context"
|
||||
"log"
|
||||
|
||||
"github.com/aquasecurity/esquery"
|
||||
"github.com/elastic/go-elasticsearch/v7"
|
||||
"github.com/aquasecurity/esquery/v8"
|
||||
"github.com/elastic/go-elasticsearch/v8"
|
||||
)
|
||||
|
||||
func main() {
|
||||
|
|
|
@ -6,7 +6,7 @@ type FilterAggregation struct {
|
|||
aggs []Aggregation
|
||||
}
|
||||
|
||||
// Filter creates a new aggregation of type "filter". The method name includes
|
||||
// FilterAgg creates a new aggregation of type "filter". The method name includes
|
||||
// the "Agg" suffix to prevent conflict with the "filter" query.
|
||||
func FilterAgg(name string, filter Mappable) *FilterAggregation {
|
||||
return &FilterAggregation{
|
||||
|
|
|
@ -44,8 +44,7 @@ func (agg *BaseAgg) Map() map[string]interface{} {
|
|||
}
|
||||
|
||||
// AvgAgg represents an aggregation of type "avg", as described in
|
||||
// https://www.elastic.co/guide/en/elasticsearch/reference/
|
||||
// current/search-aggregations-metrics-avg-aggregation.html
|
||||
// https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-avg-aggregation.html
|
||||
type AvgAgg struct {
|
||||
*BaseAgg `structs:",flatten"`
|
||||
}
|
||||
|
@ -68,8 +67,7 @@ func (agg *AvgAgg) Missing(val interface{}) *AvgAgg {
|
|||
//----------------------------------------------------------------------------//
|
||||
|
||||
// WeightedAvgAgg represents an aggregation of type "weighted_avg", as described
|
||||
// in https://www.elastic.co/guide/en/elasticsearch/reference/
|
||||
// current/search-aggregations-metrics-weight-avg-aggregation.html
|
||||
// in https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-weight-avg-aggregation.html
|
||||
type WeightedAvgAgg struct {
|
||||
name string
|
||||
apiName string
|
||||
|
@ -106,7 +104,7 @@ func (agg *WeightedAvgAgg) Value(field string, missing ...interface{}) *Weighted
|
|||
return agg
|
||||
}
|
||||
|
||||
// Value sets the weight field and optionally a value to use when records are
|
||||
// Weight sets the weight field and optionally a value to use when records are
|
||||
// missing a value for the field.
|
||||
func (agg *WeightedAvgAgg) Weight(field string, missing ...interface{}) *WeightedAvgAgg {
|
||||
agg.Weig = new(BaseAggParams)
|
||||
|
@ -128,8 +126,7 @@ func (agg *WeightedAvgAgg) Map() map[string]interface{} {
|
|||
//----------------------------------------------------------------------------//
|
||||
|
||||
// CardinalityAgg represents an aggregation of type "cardinality", as described
|
||||
// in https://www.elastic.co/guide/en/elasticsearch/reference/
|
||||
// current/search-aggregations-metrics-cardinality-aggregation.html
|
||||
// in https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-cardinality-aggregation.html
|
||||
type CardinalityAgg struct {
|
||||
*BaseAgg `structs:",flatten"`
|
||||
|
||||
|
@ -169,8 +166,7 @@ func (agg *CardinalityAgg) Map() map[string]interface{} {
|
|||
//----------------------------------------------------------------------------//
|
||||
|
||||
// MaxAgg represents an aggregation of type "max", as described in:
|
||||
// https://www.elastic.co/guide/en/elasticsearch/reference/
|
||||
// current/search-aggregations-metrics-max-aggregation.html
|
||||
// https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-max-aggregation.html
|
||||
type MaxAgg struct {
|
||||
*BaseAgg `structs:",flatten"`
|
||||
}
|
||||
|
@ -193,8 +189,7 @@ func (agg *MaxAgg) Missing(val interface{}) *MaxAgg {
|
|||
//----------------------------------------------------------------------------//
|
||||
|
||||
// MinAgg represents an aggregation of type "min", as described in:
|
||||
// https://www.elastic.co/guide/en/elasticsearch/reference/
|
||||
// current/search-aggregations-metrics-min-aggregation.html
|
||||
// https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-min-aggregation.html
|
||||
type MinAgg struct {
|
||||
*BaseAgg `structs:",flatten"`
|
||||
}
|
||||
|
@ -217,8 +212,7 @@ func (agg *MinAgg) Missing(val interface{}) *MinAgg {
|
|||
//----------------------------------------------------------------------------//
|
||||
|
||||
// SumAgg represents an aggregation of type "sum", as described in:
|
||||
// https://www.elastic.co/guide/en/elasticsearch/reference/
|
||||
// current/search-aggregations-metrics-sum-aggregation.html
|
||||
// https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-sum-aggregation.html
|
||||
type SumAgg struct {
|
||||
*BaseAgg `structs:",flatten"`
|
||||
}
|
||||
|
@ -241,8 +235,7 @@ func (agg *SumAgg) Missing(val interface{}) *SumAgg {
|
|||
//----------------------------------------------------------------------------//
|
||||
|
||||
// ValueCountAgg represents an aggregation of type "value_count", as described
|
||||
// in https://www.elastic.co/guide/en/elasticsearch/reference/
|
||||
// current/search-aggregations-metrics-valuecount-aggregation.html
|
||||
// in https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-valuecount-aggregation.html
|
||||
type ValueCountAgg struct {
|
||||
*BaseAgg `structs:",flatten"`
|
||||
}
|
||||
|
@ -258,8 +251,7 @@ func ValueCount(name, field string) *ValueCountAgg {
|
|||
//----------------------------------------------------------------------------//
|
||||
|
||||
// PercentilesAgg represents an aggregation of type "percentiles", as described
|
||||
// in https://www.elastic.co/guide/en/elasticsearch/reference/
|
||||
// current/search-aggregations-metrics-percentile-aggregation.html
|
||||
// in https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-percentile-aggregation.html
|
||||
type PercentilesAgg struct {
|
||||
*BaseAgg `structs:",flatten"`
|
||||
|
||||
|
@ -334,8 +326,7 @@ func (agg *PercentilesAgg) Map() map[string]interface{} {
|
|||
//----------------------------------------------------------------------------//
|
||||
|
||||
// StatsAgg represents an aggregation of type "stats", as described in:
|
||||
// https://www.elastic.co/guide/en/elasticsearch/reference/
|
||||
// current/search-aggregations-metrics-stats-aggregation.html
|
||||
// https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-stats-aggregation.html
|
||||
type StatsAgg struct {
|
||||
*BaseAgg `structs:",flatten"`
|
||||
}
|
||||
|
@ -357,8 +348,7 @@ func (agg *StatsAgg) Missing(val interface{}) *StatsAgg {
|
|||
// ---------------------------------------------------------------------------//
|
||||
|
||||
// StringStatsAgg represents an aggregation of type "string_stats", as described
|
||||
// in https://www.elastic.co/guide/en/elasticsearch/reference/
|
||||
// current/search-aggregations-metrics-string-stats-aggregation.html
|
||||
// in https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-string-stats-aggregation.html
|
||||
type StringStatsAgg struct {
|
||||
*BaseAgg `structs:",flatten"`
|
||||
|
||||
|
@ -399,8 +389,7 @@ func (agg *StringStatsAgg) Map() map[string]interface{} {
|
|||
// ---------------------------------------------------------------------------//
|
||||
|
||||
// TopHitsAgg represents an aggregation of type "top_hits", as described
|
||||
// in https://www.elastic.co/guide/en/elasticsearch/reference/
|
||||
// current/search-aggregations-metrics-top-hits-aggregation.html
|
||||
// in https://www.elastic.co/guide/en/elasticsearch/reference/current/search-aggregations-metrics-top-hits-aggregation.html
|
||||
type TopHitsAgg struct {
|
||||
name string
|
||||
from uint64
|
||||
|
|
|
@ -20,7 +20,7 @@ func (agg *NestedAggregation) Name() string {
|
|||
return agg.name
|
||||
}
|
||||
|
||||
// NumberOfFragments sets the aggregations path
|
||||
// Path sets the aggregations path
|
||||
func (agg *NestedAggregation) Path(p string) *NestedAggregation {
|
||||
agg.path = p
|
||||
return agg
|
||||
|
|
4
count.go
4
count.go
|
@ -4,8 +4,8 @@ import (
|
|||
"bytes"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/elastic/go-elasticsearch/v7"
|
||||
"github.com/elastic/go-elasticsearch/v7/esapi"
|
||||
"github.com/elastic/go-elasticsearch/v8"
|
||||
"github.com/elastic/go-elasticsearch/v8/esapi"
|
||||
)
|
||||
|
||||
// CountRequest represents a request to get the number of matches for a search
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
package esquery
|
||||
|
||||
import (
|
||||
"github.com/elastic/go-elasticsearch/v7"
|
||||
"github.com/elastic/go-elasticsearch/v7/esapi"
|
||||
"github.com/elastic/go-elasticsearch/v8"
|
||||
"github.com/elastic/go-elasticsearch/v8/esapi"
|
||||
)
|
||||
|
||||
// CustomQueryMap represents an arbitrary query map for custom queries.
|
||||
|
@ -21,7 +21,7 @@ func CustomQuery(m map[string]interface{}) *CustomQueryMap {
|
|||
// Map returns the custom query as a map[string]interface{}, thus implementing
|
||||
// the Mappable interface.
|
||||
func (m *CustomQueryMap) Map() map[string]interface{} {
|
||||
return map[string]interface{}(*m)
|
||||
return *m
|
||||
}
|
||||
|
||||
// Run executes the custom query using the provided ElasticSearch client. Zero
|
||||
|
|
|
@ -4,8 +4,8 @@ import (
|
|||
"bytes"
|
||||
"encoding/json"
|
||||
|
||||
"github.com/elastic/go-elasticsearch/v7"
|
||||
"github.com/elastic/go-elasticsearch/v7/esapi"
|
||||
"github.com/elastic/go-elasticsearch/v8"
|
||||
"github.com/elastic/go-elasticsearch/v8/esapi"
|
||||
)
|
||||
|
||||
// DeleteRequest represents a request to ElasticSearch's Delete By Query API,
|
||||
|
|
4
es.go
4
es.go
|
@ -32,8 +32,8 @@
|
|||
// "context"
|
||||
// "log"
|
||||
//
|
||||
// "github.com/aquasecurity/esquery"
|
||||
// "github.com/elastic/go-elasticsearch/v7"
|
||||
// "github.com/aquasecurity/esquery/v8"
|
||||
// "github.com/elastic/go-elasticsearch/v8"
|
||||
// )
|
||||
//
|
||||
// func main() {
|
||||
|
|
4
go.mod
4
go.mod
|
@ -1,9 +1,9 @@
|
|||
module github.com/okdanta/esquery
|
||||
module github.com/aquasecurity/esquery/v8
|
||||
|
||||
go 1.13
|
||||
|
||||
require (
|
||||
github.com/elastic/go-elasticsearch/v7 v7.6.0
|
||||
github.com/elastic/go-elasticsearch/v8 v8.10.1
|
||||
github.com/fatih/structs v1.1.0
|
||||
github.com/jgroeneveld/schema v1.0.0 // indirect
|
||||
github.com/jgroeneveld/trial v2.0.0+incompatible
|
||||
|
|
6
go.sum
6
go.sum
|
@ -1,5 +1,7 @@
|
|||
github.com/elastic/go-elasticsearch/v7 v7.6.0 h1:sYpGLpEFHgLUKLsZUBfuaVI9QgHjS3JdH9fX4/z8QI8=
|
||||
github.com/elastic/go-elasticsearch/v7 v7.6.0/go.mod h1:OJ4wdbtDNk5g503kvlHLyErCgQwwzmDtaFC4XyOxXA4=
|
||||
github.com/elastic/elastic-transport-go/v8 v8.3.0 h1:DJGxovyQLXGr62e9nDMPSxRyWION0Bh6d9eCFBriiHo=
|
||||
github.com/elastic/elastic-transport-go/v8 v8.3.0/go.mod h1:87Tcz8IVNe6rVSLdBux1o/PEItLtyabHU3naC7IoqKI=
|
||||
github.com/elastic/go-elasticsearch/v8 v8.10.1 h1:JJ3i2DimYTsJcUoEGbg6tNB0eehTNdid9c5kTR1TGuI=
|
||||
github.com/elastic/go-elasticsearch/v8 v8.10.1/go.mod h1:GU1BJHO7WeamP7UhuElYwzzHtvf9SDmeVpSSy9+o6Qg=
|
||||
github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo=
|
||||
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
|
||||
github.com/jgroeneveld/schema v1.0.0 h1:J0E10CrOkiSEsw6dfb1IfrDJD14pf6QLVJ3tRPl/syI=
|
||||
|
|
|
@ -252,9 +252,10 @@ func (a HighlightBoundaryScanner) String() string {
|
|||
return "sentence"
|
||||
case BoundaryScannerWord:
|
||||
return "word"
|
||||
}
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
||||
type HighlightEncoder uint8
|
||||
|
||||
|
@ -281,7 +282,7 @@ func (a HighlightEncoder) String() string {
|
|||
type HighlightFragmenter uint8
|
||||
|
||||
const (
|
||||
// FragmentSpan is the "span" value
|
||||
// FragmenterSpan is the "span" value
|
||||
FragmenterSpan HighlightFragmenter = iota
|
||||
|
||||
// FragmenterSimple is the "simple" value
|
||||
|
@ -336,6 +337,7 @@ func (a HighlightTagsSchema) String() string {
|
|||
switch a {
|
||||
case TagsSchemaStyled:
|
||||
return "styled"
|
||||
}
|
||||
default:
|
||||
return ""
|
||||
}
|
||||
}
|
||||
|
|
|
@ -32,7 +32,7 @@ func (q *BoolQuery) Filter(filter ...Mappable) *BoolQuery {
|
|||
return q
|
||||
}
|
||||
|
||||
// Must adds one or more queries of type "must_not" to the bool query. MustNot
|
||||
// MustNot adds one or more queries of type "must_not" to the bool query. MustNot
|
||||
// can be called multiple times, queries will be appended to existing ones.
|
||||
func (q *BoolQuery) MustNot(mustnot ...Mappable) *BoolQuery {
|
||||
q.mustNot = append(q.mustNot, mustnot...)
|
||||
|
|
|
@ -57,7 +57,7 @@ func (q *CombinedFieldsQuery) AutoGenerateSynonymsPhraseQuery(b bool) *CombinedF
|
|||
return q
|
||||
}
|
||||
|
||||
// Boost
|
||||
// Boost sets the query boost
|
||||
func (q *CombinedFieldsQuery) Boost(l float32) *CombinedFieldsQuery {
|
||||
q.params.Boost = l
|
||||
return q
|
||||
|
@ -83,4 +83,3 @@ func (q *CombinedFieldsQuery) ZeroTermsQuery(s ZeroTerms) *CombinedFieldsQuery {
|
|||
q.params.ZeroTerms = s
|
||||
return q
|
||||
}
|
||||
|
||||
|
|
|
@ -10,7 +10,7 @@ const (
|
|||
// TypeMatch denotes a query of type "match"
|
||||
TypeMatch matchType = iota
|
||||
|
||||
// TypeMatchBool denotes a query of type "match_bool_prefix"
|
||||
// TypeMatchBoolPrefix denotes a query of type "match_bool_prefix"
|
||||
TypeMatchBoolPrefix
|
||||
|
||||
// TypeMatchPhrase denotes a query of type "match_phrase"
|
||||
|
@ -204,9 +204,9 @@ func (q *MatchQuery) ZeroTermsQuery(s ZeroTerms) *MatchQuery {
|
|||
}
|
||||
|
||||
// Boost sets the boost value of the query.
|
||||
func (a *MatchQuery) Boost(b float32) *MatchQuery {
|
||||
a.params.Boost = b
|
||||
return a
|
||||
func (q *MatchQuery) Boost(b float32) *MatchQuery {
|
||||
q.params.Boost = b
|
||||
return q
|
||||
}
|
||||
|
||||
// MatchOperator is an enumeration type representing supported values for a
|
||||
|
|
|
@ -100,13 +100,13 @@ func (q *MultiMatchQuery) PrefixLength(l uint16) *MultiMatchQuery {
|
|||
return q
|
||||
}
|
||||
|
||||
// TieBreaker
|
||||
// TieBreaker sets the query tiebreaker
|
||||
func (q *MultiMatchQuery) TieBreaker(l float32) *MultiMatchQuery {
|
||||
q.params.TieBrk = l
|
||||
return q
|
||||
}
|
||||
|
||||
// Boost
|
||||
// Boost sets the query boost
|
||||
func (q *MultiMatchQuery) Boost(l float32) *MultiMatchQuery {
|
||||
q.params.Boost = l
|
||||
return q
|
||||
|
@ -164,27 +164,27 @@ func (q *MultiMatchQuery) ZeroTermsQuery(s ZeroTerms) *MultiMatchQuery {
|
|||
return q
|
||||
}
|
||||
|
||||
// MatchType is an enumeration type representing supported values for a
|
||||
// MultiMatchType is an enumeration type representing supported values for a
|
||||
// multi match query's "type" parameter.
|
||||
type MultiMatchType uint8
|
||||
|
||||
const (
|
||||
// TypeBestFields is the "best_fields" type
|
||||
// MatchTypeBestFields is the "best_fields" type
|
||||
MatchTypeBestFields MultiMatchType = iota
|
||||
|
||||
// TypeMostFields is the "most_fields" type
|
||||
// MatchTypeMostFields is the "most_fields" type
|
||||
MatchTypeMostFields
|
||||
|
||||
// TypeMostFields is the "cross_fields" type
|
||||
// MatchTypeCrossFields is the "cross_fields" type
|
||||
MatchTypeCrossFields
|
||||
|
||||
// TypeMostFields is the "phrase" type
|
||||
// MatchTypePhrase is the "phrase" type
|
||||
MatchTypePhrase
|
||||
|
||||
// TypeMostFields is the "phrase_prefix" type
|
||||
// MatchTypePhrasePrefix is the "phrase_prefix" type
|
||||
MatchTypePhrasePrefix
|
||||
|
||||
// TypeMostFields is the "bool_prefix" type
|
||||
// MatchTypeBoolPrefix is the "bool_prefix" type
|
||||
MatchTypeBoolPrefix
|
||||
)
|
||||
|
||||
|
|
|
@ -122,7 +122,7 @@ func (a *RangeQuery) Gt(val interface{}) *RangeQuery {
|
|||
return a
|
||||
}
|
||||
|
||||
// Gt sets that the value of field must be greater than or equal to the provided
|
||||
// Gte sets that the value of field must be greater than or equal to the provided
|
||||
// value
|
||||
func (a *RangeQuery) Gte(val interface{}) *RangeQuery {
|
||||
a.params.Gte = val
|
||||
|
@ -454,7 +454,7 @@ func (q *TermsQuery) Boost(b float32) *TermsQuery {
|
|||
|
||||
// Map returns a map representation of the query, thus implementing the
|
||||
// Mappable interface.
|
||||
func (q TermsQuery) Map() map[string]interface{} {
|
||||
func (q *TermsQuery) Map() map[string]interface{} {
|
||||
innerMap := map[string]interface{}{q.field: q.values}
|
||||
if q.boost > 0 {
|
||||
innerMap["boost"] = q.boost
|
||||
|
@ -511,7 +511,7 @@ func (q *TermsSetQuery) MinimumShouldMatchScript(script string) *TermsSetQuery {
|
|||
|
||||
// Map returns a map representation of the query, thus implementing the
|
||||
// Mappable interface.
|
||||
func (q TermsSetQuery) Map() map[string]interface{} {
|
||||
func (q *TermsSetQuery) Map() map[string]interface{} {
|
||||
return map[string]interface{}{
|
||||
"terms_set": map[string]interface{}{
|
||||
q.field: structs.Map(q.params),
|
||||
|
@ -519,7 +519,7 @@ func (q TermsSetQuery) Map() map[string]interface{} {
|
|||
}
|
||||
}
|
||||
|
||||
// geoFilterParams represents a query of type "geo_distance", as described in:
|
||||
// GeoFilter geoFilterParams represents a query of type "geo_distance", as described in:
|
||||
// https://www.elastic.co/guide/en/elasticsearch/reference/7.17/query-dsl-geo-distance-query.html
|
||||
type GeoFilter struct {
|
||||
params geoFilterParams
|
||||
|
|
|
@ -4,10 +4,10 @@ import (
|
|||
"bytes"
|
||||
"encoding/json"
|
||||
"fmt"
|
||||
"github.com/elastic/go-elasticsearch/v8"
|
||||
"time"
|
||||
|
||||
"github.com/elastic/go-elasticsearch/v7"
|
||||
"github.com/elastic/go-elasticsearch/v7/esapi"
|
||||
"github.com/elastic/go-elasticsearch/v8/esapi"
|
||||
)
|
||||
|
||||
// SearchRequest represents a request to ElasticSearch's Search API, described
|
||||
|
|
Loading…
Reference in New Issue