summaryrefslogtreecommitdiffstats
path: root/vendor/gopkg.in/olivere/elastic.v5/bulk_index_request.go
diff options
context:
space:
mode:
Diffstat (limited to 'vendor/gopkg.in/olivere/elastic.v5/bulk_index_request.go')
-rw-r--r--vendor/gopkg.in/olivere/elastic.v5/bulk_index_request.go102
1 files changed, 58 insertions, 44 deletions
diff --git a/vendor/gopkg.in/olivere/elastic.v5/bulk_index_request.go b/vendor/gopkg.in/olivere/elastic.v5/bulk_index_request.go
index 1c9302881..321d2e25a 100644
--- a/vendor/gopkg.in/olivere/elastic.v5/bulk_index_request.go
+++ b/vendor/gopkg.in/olivere/elastic.v5/bulk_index_request.go
@@ -4,6 +4,8 @@
package elastic
+//go:generate easyjson bulk_index_request.go
+
import (
"encoding/json"
"fmt"
@@ -12,7 +14,7 @@ import (
// BulkIndexRequest is a request to add a document to 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 BulkIndexRequest struct {
BulkableRequest
@@ -27,9 +29,27 @@ type BulkIndexRequest struct {
doc interface{}
pipeline string
retryOnConflict *int
- ttl string
source []string
+
+ useEasyJSON bool
+}
+
+//easyjson:json
+type bulkIndexRequestCommand map[string]bulkIndexRequestCommandOp
+
+//easyjson:json
+type bulkIndexRequestCommandOp struct {
+ Index string `json:"_index,omitempty"`
+ Id string `json:"_id,omitempty"`
+ Type string `json:"_type,omitempty"`
+ Parent string `json:"parent,omitempty"`
+ // RetryOnConflict is "_retry_on_conflict" for 6.0 and "retry_on_conflict" for 6.1+.
+ RetryOnConflict *int `json:"retry_on_conflict,omitempty"`
+ Routing string `json:"routing,omitempty"`
+ Version int64 `json:"version,omitempty"`
+ VersionType string `json:"version_type,omitempty"`
+ Pipeline string `json:"pipeline,omitempty"`
}
// NewBulkIndexRequest returns a new BulkIndexRequest.
@@ -40,6 +60,16 @@ func NewBulkIndexRequest() *BulkIndexRequest {
}
}
+// 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 *BulkIndexRequest) UseEasyJSON(enable bool) *BulkIndexRequest {
+ r.useEasyJSON = enable
+ return r
+}
+
// Index specifies the Elasticsearch index to use for this index request.
// If unspecified, the index set on the BulkService will be used.
func (r *BulkIndexRequest) Index(index string) *BulkIndexRequest {
@@ -65,7 +95,7 @@ func (r *BulkIndexRequest) Id(id string) *BulkIndexRequest {
// OpType specifies if this request should follow create-only or upsert
// behavior. This follows the OpType of the standard document index API.
-// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-index_.html#operation-type
+// See https://www.elastic.co/guide/en/elasticsearch/reference/6.0/docs-index_.html#operation-type
// for details.
func (r *BulkIndexRequest) OpType(opType string) *BulkIndexRequest {
r.opType = opType
@@ -98,7 +128,7 @@ func (r *BulkIndexRequest) Version(version int64) *BulkIndexRequest {
// VersionType specifies how versions are created. It can be e.g. internal,
// external, external_gte, or force.
//
-// See https://www.elastic.co/guide/en/elasticsearch/reference/5.2/docs-index_.html#index-versioning
+// See https://www.elastic.co/guide/en/elasticsearch/reference/6.0/docs-index_.html#index-versioning
// for details.
func (r *BulkIndexRequest) VersionType(versionType string) *BulkIndexRequest {
r.versionType = versionType
@@ -120,13 +150,6 @@ func (r *BulkIndexRequest) RetryOnConflict(retryOnConflict int) *BulkIndexReques
return r
}
-// TTL is an expiration time for the document.
-func (r *BulkIndexRequest) TTL(ttl string) *BulkIndexRequest {
- r.ttl = ttl
- r.source = nil
- return r
-}
-
// Pipeline to use while processing the request.
func (r *BulkIndexRequest) Pipeline(pipeline string) *BulkIndexRequest {
r.pipeline = pipeline
@@ -146,7 +169,7 @@ func (r *BulkIndexRequest) String() string {
// Source returns the on-wire representation of the index 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 *BulkIndexRequest) Source() ([]string, error) {
// { "index" : { "_index" : "test", "_type" : "type1", "_id" : "1" } }
@@ -159,44 +182,35 @@ func (r *BulkIndexRequest) Source() ([]string, error) {
lines := make([]string, 2)
// "index" ...
- command := make(map[string]interface{})
- indexCommand := make(map[string]interface{})
- if r.index != "" {
- indexCommand["_index"] = r.index
- }
- if r.typ != "" {
- indexCommand["_type"] = r.typ
- }
- if r.id != "" {
- indexCommand["_id"] = r.id
- }
- if r.routing != "" {
- indexCommand["_routing"] = r.routing
- }
- if r.parent != "" {
- indexCommand["_parent"] = r.parent
- }
- if r.version > 0 {
- indexCommand["_version"] = r.version
+ indexCommand := bulkIndexRequestCommandOp{
+ Index: r.index,
+ Type: r.typ,
+ Id: r.id,
+ Routing: r.routing,
+ Parent: r.parent,
+ Version: r.version,
+ VersionType: r.versionType,
+ RetryOnConflict: r.retryOnConflict,
+ Pipeline: r.pipeline,
}
- if r.versionType != "" {
- indexCommand["_version_type"] = r.versionType
+ command := bulkIndexRequestCommand{
+ r.opType: indexCommand,
}
- if r.retryOnConflict != nil {
- indexCommand["_retry_on_conflict"] = *r.retryOnConflict
- }
- if r.ttl != "" {
- indexCommand["_ttl"] = r.ttl
- }
- if r.pipeline != "" {
- indexCommand["pipeline"] = r.pipeline
+
+ var err error
+ var body []byte
+ if r.useEasyJSON {
+ // easyjson
+ body, err = command.MarshalJSON()
+ } else {
+ // encoding/json
+ body, err = json.Marshal(command)
}
- command[r.opType] = indexCommand
- line, err := json.Marshal(command)
if err != nil {
return nil, err
}
- lines[0] = string(line)
+
+ lines[0] = string(body)
// "field1" ...
if r.doc != nil {