Do executes the request and returns response or error.
(providedCtx context.Context, transport Transport)
| 85 | |
| 86 | // Do executes the request and returns response or error. |
| 87 | func (r IndexRequest) Do(providedCtx context.Context, transport Transport) (*Response, error) { |
| 88 | var ( |
| 89 | method string |
| 90 | path strings.Builder |
| 91 | params map[string]string |
| 92 | ctx context.Context |
| 93 | ) |
| 94 | |
| 95 | if instrument, ok := r.Instrument.(Instrumentation); ok { |
| 96 | ctx = instrument.Start(providedCtx, "index") |
| 97 | defer instrument.Close(ctx) |
| 98 | } |
| 99 | if ctx == nil { |
| 100 | ctx = providedCtx |
| 101 | } |
| 102 | |
| 103 | if r.DocumentID != "" { |
| 104 | method = "PUT" |
| 105 | } else { |
| 106 | method = "POST" |
| 107 | } |
| 108 | |
| 109 | path.Grow(7 + 1 + len(r.Index) + 1 + len("_doc") + 1 + len(r.DocumentID)) |
| 110 | path.WriteString("http://") |
| 111 | path.WriteString("/") |
| 112 | path.WriteString(r.Index) |
| 113 | if instrument, ok := r.Instrument.(Instrumentation); ok { |
| 114 | instrument.RecordPathPart(ctx, "index", r.Index) |
| 115 | } |
| 116 | path.WriteString("/") |
| 117 | path.WriteString("_doc") |
| 118 | if r.DocumentID != "" { |
| 119 | path.WriteString("/") |
| 120 | path.WriteString(r.DocumentID) |
| 121 | if instrument, ok := r.Instrument.(Instrumentation); ok { |
| 122 | instrument.RecordPathPart(ctx, "id", r.DocumentID) |
| 123 | } |
| 124 | } |
| 125 | |
| 126 | params = make(map[string]string) |
| 127 | |
| 128 | if r.IfPrimaryTerm != nil { |
| 129 | params["if_primary_term"] = strconv.FormatInt(*r.IfPrimaryTerm, 10) |
| 130 | } |
| 131 | |
| 132 | if r.IfSeqNo != nil { |
| 133 | params["if_seq_no"] = strconv.FormatInt(*r.IfSeqNo, 10) |
| 134 | } |
| 135 | |
| 136 | if r.IncludeSourceOnError != nil { |
| 137 | params["include_source_on_error"] = strconv.FormatBool(*r.IncludeSourceOnError) |
| 138 | } |
| 139 | |
| 140 | if r.OpType != "" { |
| 141 | params["op_type"] = r.OpType |
| 142 | } |
| 143 | |
| 144 | if r.Pipeline != "" { |
no test coverage detected