func FormatEsIndices(esIndices []EsIndex, prefix, postfix string) string {
	output := ""
	for _, index := range esIndices {
		output = fmt.Sprintf("%s%s%s%s", output, prefix, index.Index, postfix)
	}
	return output
}
FormatEsIndices formats the ES Indices information to print it or something
esIndices: indices to format
prefix: a prefix for each ES index
postfix: a postfix for each ES index
package elasticsearch
import (
	"bytes"
	"encoding/json"
	"fmt"
	"io/ioutil"
	"net/http"
)
type EsConnection struct {
	Port      string
	URL       string
	Namespace string
}
type EsSpan struct {
	ID            string
	ServiceName   string
	OperationName string
}
func (connection *EsConnection) PrettyString(callback func(args ...interface{})) {
	callback("ElasticSearch connection details:")
	callback(fmt.Sprintf("\t * Port: %s", connection.Port))
	callback(fmt.Sprintf("\t * URL: %s", connection.URL))
	callback(fmt.Sprintf("\t * Namespace: %s", connection.Namespace))
}
type EsIndex struct {
	Index string `json:"index"`
	es    EsConnection
}
func (index *EsIndex) GetServiceIndexSpans(serviceName string) ([]EsSpan, error) {
	spans, err := index.GetIndexSpans()
	if err != nil {
		return []EsSpan{}, err
	}
	filteredSpans := []EsSpan{}
	for _, span := range spans {
		if span.ServiceName == serviceName {
			filteredSpans = append(filteredSpans, span)
		}
	}
	return filteredSpans, nil
}
func (index *EsIndex) GetIndexSpans() ([]EsSpan, error) {
	searchResponse := struct {
		Hits struct {
			Hits []struct {
				ID     string `json:"_id"`
				Source struct {
					Process struct {
						ServiceName string `json:"serviceName"`
					} `json:"process"`
					OperationName string `json:"operationName"`
				} `json:"_source"`
			} `json:"hits"`
		} `json:"hits"`
	}{}
	body := struct {
		Query struct {
			QueryString struct {
				Query string `json:"query"`
			} `json:"query_string"`
		} `json:"query"`
		Size int `json:"size"`
		From int `json:"from"`
	}{}
	body.From = 0
	body.Size = 10000
	body.Query.QueryString.Query = "*"
	bodyReq, _ := json.Marshal(body)
	bodyBytes, err := executeEsRequest(index.es, http.MethodPost, fmt.Sprintf("/%s/_search?format=json", index.Index), bodyReq)
	if err != nil {
		return []EsSpan{}, fmt.Errorf(fmt.Sprintf("Something failed while quering the ES REST API: %s", err))
	}
	err = json.Unmarshal(bodyBytes, &searchResponse)
	if err != nil {
		return []EsSpan{}, fmt.Errorf(fmt.Sprintf("Something failed while unmarshalling API response: %s", err))
	}
	spans := []EsSpan{}
	for _, jsonSpan := range searchResponse.Hits.Hits {
		span := EsSpan{ID: jsonSpan.ID, ServiceName: jsonSpan.Source.Process.ServiceName, OperationName: jsonSpan.Source.OperationName}
		spans = append(spans, span)
	}
	return spans, nil
}
func CheckESConnection(es EsConnection) error {
	_, err := executeEsRequest(es, http.MethodGet, "/", nil)
	if err != nil {
		return fmt.Errorf(fmt.Sprint("There was a problem while connecting to the ES instance: ", err))
	}
	return nil
}