Do executes the request and returns response or error.
(providedCtx context.Context, transport Transport)
| 83 | |
| 84 | // Do executes the request and returns response or error. |
| 85 | func (r BulkRequest) Do(providedCtx context.Context, transport Transport) (*Response, error) { |
| 86 | var ( |
| 87 | method string |
| 88 | path strings.Builder |
| 89 | params map[string]string |
| 90 | ctx context.Context |
| 91 | ) |
| 92 | |
| 93 | if instrument, ok := r.Instrument.(Instrumentation); ok { |
| 94 | ctx = instrument.Start(providedCtx, "bulk") |
| 95 | defer instrument.Close(ctx) |
| 96 | } |
| 97 | if ctx == nil { |
| 98 | ctx = providedCtx |
| 99 | } |
| 100 | |
| 101 | method = "POST" |
| 102 | |
| 103 | path.Grow(7 + 1 + len(r.Index) + 1 + len("_bulk")) |
| 104 | path.WriteString("http://") |
| 105 | if r.Index != "" { |
| 106 | path.WriteString("/") |
| 107 | path.WriteString(r.Index) |
| 108 | if instrument, ok := r.Instrument.(Instrumentation); ok { |
| 109 | instrument.RecordPathPart(ctx, "index", r.Index) |
| 110 | } |
| 111 | } |
| 112 | path.WriteString("/") |
| 113 | path.WriteString("_bulk") |
| 114 | |
| 115 | params = make(map[string]string) |
| 116 | |
| 117 | if r.IncludeSourceOnError != nil { |
| 118 | params["include_source_on_error"] = strconv.FormatBool(*r.IncludeSourceOnError) |
| 119 | } |
| 120 | |
| 121 | if r.ListExecutedPipelines != nil { |
| 122 | params["list_executed_pipelines"] = strconv.FormatBool(*r.ListExecutedPipelines) |
| 123 | } |
| 124 | |
| 125 | if r.Pipeline != "" { |
| 126 | params["pipeline"] = r.Pipeline |
| 127 | } |
| 128 | |
| 129 | if r.Refresh != "" { |
| 130 | params["refresh"] = r.Refresh |
| 131 | } |
| 132 | |
| 133 | if r.RequireAlias != nil { |
| 134 | params["require_alias"] = strconv.FormatBool(*r.RequireAlias) |
| 135 | } |
| 136 | |
| 137 | if r.RequireDataStream != nil { |
| 138 | params["require_data_stream"] = strconv.FormatBool(*r.RequireDataStream) |
| 139 | } |
| 140 | |
| 141 | if len(r.Routing) > 0 { |
| 142 | params["routing"] = strings.Join(r.Routing, ",") |