Support Elasticsearch v8

This commit is contained in:
Roman 2022-09-22 15:04:03 +03:00
parent 49a92fc25e
commit 5761bdcd5d
8 changed files with 19 additions and 21 deletions

View File

@ -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: `esquery` is a Go module. To install, simply run this in your project's root directory:
```bash ```bash
go get github.com/aquasecurity/esquery go get github.com/aquasecurity/esquery/v8
``` ```
## Usage ## Usage
@ -51,8 +51,8 @@ import (
"context" "context"
"log" "log"
"github.com/aquasecurity/esquery" "github.com/aquasecurity/esquery/v8"
"github.com/elastic/go-elasticsearch/v7" "github.com/elastic/go-elasticsearch/v8"
) )
func main() { func main() {

View File

@ -4,8 +4,8 @@ import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"github.com/elastic/go-elasticsearch/v7" "github.com/elastic/go-elasticsearch/v8"
"github.com/elastic/go-elasticsearch/v7/esapi" "github.com/elastic/go-elasticsearch/v8/esapi"
) )
// CountRequest represents a request to get the number of matches for a search // CountRequest represents a request to get the number of matches for a search

View File

@ -1,8 +1,8 @@
package esquery package esquery
import ( import (
"github.com/elastic/go-elasticsearch/v7" "github.com/elastic/go-elasticsearch/v8"
"github.com/elastic/go-elasticsearch/v7/esapi" "github.com/elastic/go-elasticsearch/v8/esapi"
) )
// CustomQueryMap represents an arbitrary query map for custom queries. // CustomQueryMap represents an arbitrary query map for custom queries.

View File

@ -4,8 +4,8 @@ import (
"bytes" "bytes"
"encoding/json" "encoding/json"
"github.com/elastic/go-elasticsearch/v7" "github.com/elastic/go-elasticsearch/v8"
"github.com/elastic/go-elasticsearch/v7/esapi" "github.com/elastic/go-elasticsearch/v8/esapi"
) )
// DeleteRequest represents a request to ElasticSearch's Delete By Query API, // DeleteRequest represents a request to ElasticSearch's Delete By Query API,

4
es.go
View File

@ -32,8 +32,8 @@
// "context" // "context"
// "log" // "log"
// //
// "github.com/aquasecurity/esquery" // "github.com/aquasecurity/esquery/v8"
// "github.com/elastic/go-elasticsearch/v7" // "github.com/elastic/go-elasticsearch/v8"
// ) // )
// //
// func main() { // func main() {

4
go.mod
View File

@ -1,9 +1,9 @@
module github.com/aquasecurity/esquery module github.com/aquasecurity/esquery/v8
go 1.13 go 1.13
require ( require (
github.com/elastic/go-elasticsearch/v7 v7.6.0 github.com/elastic/go-elasticsearch/v8 v8.4.0
github.com/fatih/structs v1.1.0 github.com/fatih/structs v1.1.0
github.com/jgroeneveld/schema v1.0.0 // indirect github.com/jgroeneveld/schema v1.0.0 // indirect
github.com/jgroeneveld/trial v2.0.0+incompatible github.com/jgroeneveld/trial v2.0.0+incompatible

6
go.sum
View File

@ -1,5 +1,7 @@
github.com/elastic/go-elasticsearch/v7 v7.6.0 h1:sYpGLpEFHgLUKLsZUBfuaVI9QgHjS3JdH9fX4/z8QI8= github.com/elastic/elastic-transport-go/v8 v8.1.0 h1:NeqEz1ty4RQz+TVbUrpSU7pZ48XkzGWQj02k5koahIE=
github.com/elastic/go-elasticsearch/v7 v7.6.0/go.mod h1:OJ4wdbtDNk5g503kvlHLyErCgQwwzmDtaFC4XyOxXA4= github.com/elastic/elastic-transport-go/v8 v8.1.0/go.mod h1:87Tcz8IVNe6rVSLdBux1o/PEItLtyabHU3naC7IoqKI=
github.com/elastic/go-elasticsearch/v8 v8.4.0 h1:Rn1mcqaIMcNT43hnx2H62cIFZ+B6mjWtzj85BDKrvCE=
github.com/elastic/go-elasticsearch/v8 v8.4.0/go.mod h1:yY52i2Vj0unLz+N3Nwx1gM5LXwoj3h2dgptNGBYkMLA=
github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo= github.com/fatih/structs v1.1.0 h1:Q7juDM0QtcnhCpeyLGQKyg4TOIghuNXrkL32pHAUMxo=
github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M= github.com/fatih/structs v1.1.0/go.mod h1:9NiDSp5zOcgEDl+j00MP/WkGVPOlPRLejGD8Ga6PJ7M=
github.com/jgroeneveld/schema v1.0.0 h1:J0E10CrOkiSEsw6dfb1IfrDJD14pf6QLVJ3tRPl/syI= github.com/jgroeneveld/schema v1.0.0 h1:J0E10CrOkiSEsw6dfb1IfrDJD14pf6QLVJ3tRPl/syI=

View File

@ -6,8 +6,8 @@ import (
"fmt" "fmt"
"time" "time"
"github.com/elastic/go-elasticsearch/v7" "github.com/elastic/go-elasticsearch/v8"
"github.com/elastic/go-elasticsearch/v7/esapi" "github.com/elastic/go-elasticsearch/v8/esapi"
) )
// SearchRequest represents a request to ElasticSearch's Search API, described // SearchRequest represents a request to ElasticSearch's Search API, described
@ -26,7 +26,6 @@ type SearchRequest struct {
sort Sort sort Sort
source Source source Source
timeout *time.Duration timeout *time.Duration
} }
// Search creates a new SearchRequest object, to be filled via method chaining. // Search creates a new SearchRequest object, to be filled via method chaining.
@ -113,8 +112,6 @@ func (req *SearchRequest) Highlight(highlight Mappable) *SearchRequest {
return req return req
} }
// Map implements the Mappable interface. It converts the request to into a // Map implements the Mappable interface. It converts the request to into a
// nested map[string]interface{}, as expected by the go-elasticsearch library. // nested map[string]interface{}, as expected by the go-elasticsearch library.
func (req *SearchRequest) Map() map[string]interface{} { func (req *SearchRequest) Map() map[string]interface{} {
@ -155,7 +152,6 @@ func (req *SearchRequest) Map() map[string]interface{} {
m["search_after"] = req.searchAfter m["search_after"] = req.searchAfter
} }
source := req.source.Map() source := req.source.Map()
if len(source) > 0 { if len(source) > 0 {
m["_source"] = source m["_source"] = source