in testing/estools/elasticsearch.go [421:465]
func CheckForErrorsInLogsWithContext(ctx context.Context, client elastictransport.Interface, namespace string, excludeStrings []string) (Documents, error) {
filters := map[string]interface{}{
"must": []map[string]interface{}{
{
"match": map[string]interface{}{
"log.level": "error",
},
},
{
"term": map[string]interface{}{
"data_stream.namespace": map[string]interface{}{
"value": namespace,
},
},
},
},
}
if len(excludeStrings) > 0 {
excludeStatements := []map[string]interface{}{}
for _, ex := range excludeStrings {
excludeStatements = append(excludeStatements, map[string]interface{}{
"match_phrase": map[string]interface{}{
"message": ex,
},
})
}
filters["must_not"] = excludeStatements
}
queryRaw := map[string]interface{}{
"query": map[string]interface{}{
"bool": filters,
},
}
var buf bytes.Buffer
err := json.NewEncoder(&buf).Encode(queryRaw)
if err != nil {
return Documents{}, fmt.Errorf("error creating ES query: %w", err)
}
return PerformQueryForRawQuery(ctx, queryRaw, "logs-elastic_agent*", client)
}