in action/log/logadapter/elasticsearch.go [208:246]
func getEsIndexList(currency *Currency) ([]string, error) {
es, err := createEsDefaultClient(currency)
if err != nil {
return nil, fmt.Errorf("failed to create Elasticsearch client: %w", err)
}
// Build the request to get the mappings
req := esapi.IndicesGetMappingRequest{
Index: []string{currency.Source}, // Specify the index name
}
// Execute the request
res, err := req.Do(context.Background(), es)
if err != nil {
return nil, fmt.Errorf("error getting mapping: %s", err)
}
defer func(Body io.ReadCloser) {
err := Body.Close()
if err != nil {
tool.Logger.Error("error closing body")
}
}(res.Body)
// Check if the response is successful
if res.IsError() {
return nil, fmt.Errorf("error response: %s", res.String())
}
// Read and parse the response
var result map[string]interface{}
if err := json.NewDecoder(res.Body).Decode(&result); err != nil {
return nil, fmt.Errorf("failed to make request to %s", err)
}
// Call method to extract field names
indexFields := extractFields(result)
indexFields = removeKeywordSuffix(indexFields)
return indexFields, nil
}