MCPcopy
hub / github.com/elastic/go-elasticsearch / Do

Method Do

esapi/api.index.go:87–256  ·  view source on GitHub ↗

Do executes the request and returns response or error.

(providedCtx context.Context, transport Transport)

Source from the content-addressed store, hash-verified

85
86// Do executes the request and returns response or error.
87func (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 != "" {

Callers 1

mainFunction · 0.95

Calls 15

formatDurationFunction · 0.85
newRequestFunction · 0.85
JoinMethod · 0.80
CloseMethod · 0.65
AddMethod · 0.65
PerformMethod · 0.65
StartMethod · 0.45
RecordPathPartMethod · 0.45
StringMethod · 0.45
RecordErrorMethod · 0.45
QueryMethod · 0.45
SetMethod · 0.45

Tested by

no test coverage detected