# QueryStringProps

Properties for a QueryString.

Used as props by: [QueryString](/cdk/api/v2/docs/aws-cdk-lib.aws_logs.QueryString.html)

- Source: [`aws-logs/lib/query-definition.ts`](https://github.com/aws/aws-cdk/blob/v2.277.0/packages/aws-cdk-lib/aws-logs/lib/query-definition.ts#L12)
- Type last changed: v2.208.0 · 29 Jul 2025

## Example

TypeScript:

```ts
new logs.QueryDefinition(this, 'QueryDefinition', {
  queryDefinitionName: 'MyQuery',
  queryString: new logs.QueryString({
    fields: ['@timestamp', '@message'],
    parseStatements: [
      '@message "[*] *" as loggingType, loggingMessage',
      '@message "<*>: *" as differentLoggingType, differentLoggingMessage',
    ],
    filterStatements: [
      'loggingType = "ERROR"',
      'loggingMessage = "A very strange error occurred!"',
    ],
    statsStatements: [
      'count(loggingMessage) as loggingErrors',
      'count(differentLoggingMessage) as differentLoggingErrors',
    ],
    sort: '@timestamp desc',
    limit: 20,
  }),
});
```

Python:

```python
logs.QueryDefinition(self, "QueryDefinition",
    query_definition_name="MyQuery",
    query_string=logs.QueryString(
        fields=["@timestamp", "@message"],
        parse_statements=["@message \"[*] *\" as loggingType, loggingMessage", "@message \"<*>: *\" as differentLoggingType, differentLoggingMessage"
        ],
        filter_statements=["loggingType = \"ERROR\"", "loggingMessage = \"A very strange error occurred!\""
        ],
        stats_statements=["count(loggingMessage) as loggingErrors", "count(differentLoggingMessage) as differentLoggingErrors"
        ],
        sort="@timestamp desc",
        limit=20
    )
)
```

Java:

```java
QueryDefinition.Builder.create(this, "QueryDefinition")
        .queryDefinitionName("MyQuery")
        .queryString(QueryString.Builder.create()
                .fields(List.of("@timestamp", "@message"))
                .parseStatements(List.of("@message \"[*] *\" as loggingType, loggingMessage", "@message \"<*>: *\" as differentLoggingType, differentLoggingMessage"))
                .filterStatements(List.of("loggingType = \"ERROR\"", "loggingMessage = \"A very strange error occurred!\""))
                .statsStatements(List.of("count(loggingMessage) as loggingErrors", "count(differentLoggingMessage) as differentLoggingErrors"))
                .sort("@timestamp desc")
                .limit(20)
                .build())
        .build();
```

C# / .NET:

```csharp
// Install: dotnet add package Amazon.CDK.Lib
new QueryDefinition(this, "QueryDefinition", new QueryDefinitionProps {
    QueryDefinitionName = "MyQuery",
    QueryString = new QueryString(new QueryStringProps {
        Fields = new [] { "@timestamp", "@message" },
        ParseStatements = new [] { "@message \"[*] *\" as loggingType, loggingMessage", "@message \"<*>: *\" as differentLoggingType, differentLoggingMessage" },
        FilterStatements = new [] { "loggingType = \"ERROR\"", "loggingMessage = \"A very strange error occurred!\"" },
        StatsStatements = new [] { "count(loggingMessage) as loggingErrors", "count(differentLoggingMessage) as differentLoggingErrors" },
        Sort = "@timestamp desc",
        Limit = 20
    })
});
```

Golang:

```go
// Install: go get github.com/aws/aws-cdk-go/awscdk/v2
logs.NewQueryDefinition(this, jsii.String("QueryDefinition"), &QueryDefinitionProps{
	QueryDefinitionName: jsii.String("MyQuery"),
	QueryString: logs.NewQueryString(&QueryStringProps{
		Fields: []*string{
			jsii.String("@timestamp"),
			jsii.String("@message"),
		},
		ParseStatements: []*string{
			jsii.String("@message \"[*] *\" as loggingType, loggingMessage"),
			jsii.String("@message \"<*>: *\" as differentLoggingType, differentLoggingMessage"),
		},
		FilterStatements: []*string{
			jsii.String("loggingType = \"ERROR\""),
			jsii.String("loggingMessage = \"A very strange error occurred!\""),
		},
		StatsStatements: []*string{
			jsii.String("count(loggingMessage) as loggingErrors"),
			jsii.String("count(differentLoggingMessage) as differentLoggingErrors"),
		},
		Sort: jsii.String("@timestamp desc"),
		Limit: jsii.Number(20),
	}),
})
```

## Properties

- `display`: string — Specifies which fields to display in the query results.

  **Default:** no display in QueryString

- `fields`: string[] — Retrieves the specified fields from log events for display.

  **Default:** no fields in QueryString

- `filter`: string — Use `filterStatements` instead

  **Default:** no filter in QueryString

- `filterStatements`: string[] — An array of one or more statements for filtering the results of a query based on a boolean expression.

  **Default:** no filter in QueryString

  Each provided statement generates a separate filter line in the query string.

  Note: If provided, this property overrides any value provided for the `filter` property.

- `limit`: number — Specifies the number of log events returned by the query.

  **Default:** no limit in QueryString

- `parse`: string — Use `parseStatements` instead

  **Default:** no parse in QueryString

- `parseStatements`: string[] — An array of one or more statements for parsing data from a log field and creating ephemeral fields that can be processed further in the query.

  **Default:** no parse in QueryString

  Each provided statement generates a separate
  parse line in the query string.

  Note: If provided, this property overrides any value provided for the `parse` property.

- `sort`: string — Sorts the retrieved log events.

  **Default:** no sort in QueryString

- `stats`: string — Use `statsStatements` instead

  **Default:** no stats in QueryString

- `statsStatements`: string[] — An array of one or more statements for calculating aggregate statistics.

  **Default:** no stats in QueryString

  CloudWatch Logs Insights supports up to two stats commands in a single query.
  Each provided statement generates a separate stats line in the query string.

  Note: If provided, this property overrides any value provided for the `stats` property.
