in compliance/elasticsearch.go [65:94]
func (es *Elasticsearch) IndexTemplate(name string) (*IndexTemplate, error) {
resp, err := es.client.Indices.GetIndexTemplate(
es.client.Indices.GetIndexTemplate.WithContext(context.TODO()),
es.client.Indices.GetIndexTemplate.WithName(name),
)
if err != nil {
return nil, err
}
defer resp.Body.Close()
if resp.StatusCode != http.StatusOK {
return nil, fmt.Errorf("HTTP status code %d", resp.StatusCode)
}
var templatesResponse struct {
IndexTemplates []struct {
IndexTemplate *IndexTemplate `json:"index_template"`
} `json:"index_templates"`
}
err = newJSONDecoder(resp.Body).Decode(&templatesResponse)
if err != nil {
return nil, err
}
if n := len(templatesResponse.IndexTemplates); n != 1 {
return nil, fmt.Errorf("one index template expected, found %d", n)
}
return templatesResponse.IndexTemplates[0].IndexTemplate, nil
}