diff options
Diffstat (limited to 'vendor/gopkg.in/olivere/elastic.v5/bulk_delete_request.go')
-rw-r--r-- | vendor/gopkg.in/olivere/elastic.v5/bulk_delete_request.go | 81 |
1 files changed, 51 insertions, 30 deletions
diff --git a/vendor/gopkg.in/olivere/elastic.v5/bulk_delete_request.go b/vendor/gopkg.in/olivere/elastic.v5/bulk_delete_request.go index 5d4a2a5a7..e6c98c553 100644 --- a/vendor/gopkg.in/olivere/elastic.v5/bulk_delete_request.go +++ b/vendor/gopkg.in/olivere/elastic.v5/bulk_delete_request.go @@ -4,6 +4,8 @@ package elastic +//go:generate easyjson bulk_delete_request.go + import ( "encoding/json" "fmt" @@ -14,7 +16,7 @@ import ( // BulkDeleteRequest is a request to remove a document from Elasticsearch. // -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-bulk.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.0/docs-bulk.html // for details. type BulkDeleteRequest struct { BulkableRequest @@ -27,6 +29,22 @@ type BulkDeleteRequest struct { versionType string // default is "internal" source []string + + useEasyJSON bool +} + +//easyjson:json +type bulkDeleteRequestCommand map[string]bulkDeleteRequestCommandOp + +//easyjson:json +type bulkDeleteRequestCommandOp struct { + Index string `json:"_index,omitempty"` + Type string `json:"_type,omitempty"` + Id string `json:"_id,omitempty"` + Parent string `json:"parent,omitempty"` + Routing string `json:"routing,omitempty"` + Version int64 `json:"version,omitempty"` + VersionType string `json:"version_type,omitempty"` } // NewBulkDeleteRequest returns a new BulkDeleteRequest. @@ -34,6 +52,16 @@ func NewBulkDeleteRequest() *BulkDeleteRequest { return &BulkDeleteRequest{} } +// UseEasyJSON is an experimental setting that enables serialization +// with github.com/mailru/easyjson, which should in faster serialization +// time and less allocations, but removed compatibility with encoding/json, +// usage of unsafe etc. See https://github.com/mailru/easyjson#issues-notes-and-limitations +// for details. This setting is disabled by default. +func (r *BulkDeleteRequest) UseEasyJSON(enable bool) *BulkDeleteRequest { + r.useEasyJSON = enable + return r +} + // Index specifies the Elasticsearch index to use for this delete request. // If unspecified, the index set on the BulkService will be used. func (r *BulkDeleteRequest) Index(index string) *BulkDeleteRequest { @@ -81,7 +109,7 @@ func (r *BulkDeleteRequest) Version(version int64) *BulkDeleteRequest { } // VersionType can be "internal" (default), "external", "external_gte", -// "external_gt", or "force". +// or "external_gt". func (r *BulkDeleteRequest) VersionType(versionType string) *BulkDeleteRequest { r.versionType = versionType r.source = nil @@ -100,45 +128,38 @@ func (r *BulkDeleteRequest) String() string { // Source returns the on-wire representation of the delete request, // split into an action-and-meta-data line and an (optional) source line. -// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-bulk.html +// See https://www.elastic.co/guide/en/elasticsearch/reference/6.0/docs-bulk.html // for details. func (r *BulkDeleteRequest) Source() ([]string, error) { if r.source != nil { return r.source, nil } - lines := make([]string, 1) - - source := make(map[string]interface{}) - deleteCommand := make(map[string]interface{}) - if r.index != "" { - deleteCommand["_index"] = r.index + command := bulkDeleteRequestCommand{ + "delete": bulkDeleteRequestCommandOp{ + Index: r.index, + Type: r.typ, + Id: r.id, + Routing: r.routing, + Parent: r.parent, + Version: r.version, + VersionType: r.versionType, + }, } - if r.typ != "" { - deleteCommand["_type"] = r.typ - } - if r.id != "" { - deleteCommand["_id"] = r.id - } - if r.parent != "" { - deleteCommand["_parent"] = r.parent - } - if r.routing != "" { - deleteCommand["_routing"] = r.routing - } - if r.version > 0 { - deleteCommand["_version"] = r.version - } - if r.versionType != "" { - deleteCommand["_version_type"] = r.versionType - } - source["delete"] = deleteCommand - body, err := json.Marshal(source) + var err error + var body []byte + if r.useEasyJSON { + // easyjson + body, err = command.MarshalJSON() + } else { + // encoding/json + body, err = json.Marshal(command) + } if err != nil { return nil, err } - lines[0] = string(body) + lines := []string{string(body)} r.source = lines return lines, nil |