func GetLogsForDatastream()

in testing/estools/elasticsearch.go [661:710]


func GetLogsForDatastream(
	ctx context.Context,
	client elastictransport.Interface,
	dsType, dataset, namespace string) (Documents, error) {

	query := map[string]any{
		"_source": []string{"message"},
		"query": map[string]any{
			"bool": map[string]any{
				"must": []any{
					map[string]any{
						"match": map[string]any{
							"data_stream.dataset": dataset,
						},
					},
					map[string]any{
						"match": map[string]any{
							"data_stream.namespace": namespace,
						},
					},
					map[string]any{
						"match": map[string]any{
							"data_stream.type": dsType,
						},
					},
				},
			},
		},
	}

	var buf bytes.Buffer
	if err := json.NewEncoder(&buf).Encode(query); err != nil {
		return Documents{}, fmt.Errorf("error creating ES query: %w", err)
	}

	es := esapi.New(client)
	res, err := es.Search(
		es.Search.WithIndex(fmt.Sprintf(".ds-%s*", dsType)),
		es.Search.WithExpandWildcards("all"),
		es.Search.WithBody(&buf),
		es.Search.WithTrackTotalHits(true),
		es.Search.WithPretty(),
		es.Search.WithContext(ctx),
	)
	if err != nil {
		return Documents{}, fmt.Errorf("error performing ES search: %w", err)
	}

	return handleDocsResponse(res)
}