func (g gateway) WarmupIndices(ctx context.Context, indices string) ([]byte, error) {
	warmupURL, err := g.buildWarmupURL(indices)
	if err != nil {
		return nil, err
	}
	request, err := g.BuildRequest(ctx, http.MethodGet, "", warmupURL.String(), gw.GetDefaultHeaders())
	if err != nil {
		return nil, err
	}
	response, err := g.Call(request, http.StatusOK)
	if err != nil {
		return nil, processKNNError(err)
	}
	return response, nil
}
/* WarmupIndices will perform warmup on given indices
GET /_opendistro/_knn/warmup/index1,index2,index3?pretty
{
"_shards" : {
"total" : 6,
"successful" : 6,
"failed" : 0
}
}
package knn
import (
	"context"
	"encoding/json"
	"errors"
	"fmt"
	"net/http"
	"net/url"
	"odfe-cli/client"
	"odfe-cli/entity"
	"odfe-cli/entity/knn"
	gw "odfe-cli/gateway"
)
const (
	baseURL                  = "_opendistro/_knn"
	statsURL                 = baseURL + "/stats"
	nodeStatsURLTemplate     = baseURL + "/%s/stats/%s"
	warmupIndicesURLTemplate = baseURL + "/warmup/%s"
)
type Gateway interface {
	GetStatistics(ctx context.Context, nodes string, names string) ([]byte, error)
	WarmupIndices(ctx context.Context, indices string) ([]byte, error)
}
type gateway struct {
	gw.HTTPGateway
}
func New(c *client.Client, p *entity.Profile) Gateway {
	return &gateway{*gw.NewHTTPGateway(c, p)}
}
func (g *gateway) buildStatsURL(nodes string, names string) (*url.URL, error) {
	endpoint, err := gw.GetValidEndpoint(g.Profile)
	if err != nil {
		return nil, err
	}
	path := statsURL
	if nodes != "" || names != "" {
		path = fmt.Sprintf(nodeStatsURLTemplate, nodes, names)
	}
	endpoint.Path = path
	return endpoint, nil
}
func (g *gateway) buildWarmupURL(indices string) (*url.URL, error) {
	endpoint, err := gw.GetValidEndpoint(g.Profile)
	if err != nil {
		return nil, err
	}
	endpoint.Path = fmt.Sprintf(warmupIndicesURLTemplate, indices)
	return endpoint, nil
}
func (g gateway) GetStatistics(ctx context.Context, nodes string, names string) ([]byte, error) {
	statsURL, err := g.buildStatsURL(nodes, names)
	if err != nil {
		return nil, err
	}
	request, err := g.BuildRequest(ctx, http.MethodGet, "", statsURL.String(), gw.GetDefaultHeaders())
	if err != nil {
		return nil, err
	}
	response, err := g.Call(request, http.StatusOK)
	if err != nil {
		return nil, processKNNError(err)
	}
	return response, nil
}
func processKNNError(err error) error {
	var k knn.ErrorResponse
	data := fmt.Sprintf("%v", err)
	responseErr := json.Unmarshal([]byte(data), &k)
	if responseErr != nil {
		return err
	}
	if len(k.KNNError.RootCause) > 0 {
		return errors.New(k.KNNError.RootCause[0].Reason)
	}
	return err
}