diff --git a/daprdocs/content/en/developing-applications/building-blocks/state-management/howto-state-query-api.md b/daprdocs/content/en/developing-applications/building-blocks/state-management/howto-state-query-api.md index 011d8a7d8..b0e4a040c 100644 --- a/daprdocs/content/en/developing-applications/building-blocks/state-management/howto-state-query-api.md +++ b/daprdocs/content/en/developing-applications/building-blocks/state-management/howto-state-query-api.md @@ -25,7 +25,7 @@ You can find additional information in the [related links]({{< ref "#related-lin ## Querying the state You submit query requests via HTTP POST/PUT or gRPC. -The body of the request is the JSON map with 3 entries: `filter`, `sort`, and `pagination`. +The body of the request is the JSON map with 3 entries: `filter`, `sort`, and `page`. The `filter` is an optional section. It specifies the query conditions in the form of a tree of key/value operations, where the key is the operator and the value is the operands. @@ -42,7 +42,7 @@ If `filter` section is omitted, the query returns all entries. The `sort` is an optional section and is an ordered array of `key:order` pairs, where `key` is a key in the state store, and the `order` is an optional string indicating sorting order: `"ASC"` for ascending and `"DESC"` for descending. If omitted, ascending order is the default. -The `pagination` is an optional section containing `limit` and `token` parameters. `limit` sets the page size. `token` is an iteration token returned by the component, and is used in subsequent queries. +The `page` is an optional section containing `limit` and `token` parameters. `limit` sets the page size. `token` is an iteration token returned by the component, and is used in subsequent queries. For some background understanding, this query request is translated into the native query language and executed by the state store component. @@ -87,17 +87,15 @@ First, let's find all employees in the state of California and sort them by thei This is the [query](../query-api-examples/query1.json): ```json { - "query": { - "filter": { - "EQ": { "value.state": "CA" } - }, - "sort": [ - { - "key": "value.person.id", - "order": "DESC" - } - ] - } + "filter": { + "EQ": { "value.state": "CA" } + }, + "sort": [ + { + "key": "value.person.id", + "order": "DESC" + } + ] } ``` @@ -186,10 +184,8 @@ Let's now find all employees from the "Dev Ops" and "Hardware" organizations. This is the [query](../query-api-examples/query2.json): ```json { - "query": { - "filter": { - "IN": { "value.person.org": [ "Dev Ops", "Hardware" ] } - } + "filter": { + "IN": { "value.person.org": [ "Dev Ops", "Hardware" ] } } } ``` @@ -228,36 +224,34 @@ This is the [query](../query-api-examples/query3.json): ```json { - "query": { - "filter": { - "OR": [ - { - "EQ": { "value.person.org": "Dev Ops" } - }, - { - "AND": [ - { - "EQ": { "value.person.org": "Finance" } - }, - { - "IN": { "value.state": [ "CA", "WA" ] } - } - ] - } - ] - }, - "sort": [ + "filter": { + "OR": [ { - "key": "value.state", - "order": "DESC" + "EQ": { "value.person.org": "Dev Ops" } }, { - "key": "value.person.id" + "AND": [ + { + "EQ": { "value.person.org": "Finance" } + }, + { + "IN": { "value.state": [ "CA", "WA" ] } + } + ] } - ], - "pagination": { - "limit": 3 + ] + }, + "sort": [ + { + "key": "value.state", + "order": "DESC" + }, + { + "key": "value.person.id" } + ], + "page": { + "limit": 3 } } ``` @@ -336,40 +330,52 @@ The pagination token is used "as is" in the [subsequent query](../query-api-exam ```json { - "query": { - "filter": { - "OR": [ - { - "EQ": { "value.person.org": "Dev Ops" } - }, - { - "AND": [ - { - "EQ": { "value.person.org": "Finance" } - }, - { - "IN": { "value.state": [ "CA", "WA" ] } - } - ] - } - ] - }, - "sort": [ + "filter": { + "OR": [ { - "key": "value.state", - "order": "DESC" + "EQ": { "value.person.org": "Dev Ops" } }, { - "key": "value.person.id" + "AND": [ + { + "EQ": { "value.person.org": "Finance" } + }, + { + "IN": { "value.state": [ "CA", "WA" ] } + } + ] } - ], - "pagination": { - "limit": 3, - "token": "3" + ] + }, + "sort": [ + { + "key": "value.state", + "order": "DESC" + }, + { + "key": "value.person.id" } + ], + "page": { + "limit": 3, + "token": "3" } } ``` + +{{< tabs "HTTP API (Bash)" "HTTP API (PowerShell)" >}} +{{% codetab %}} +```bash +curl -s -X POST -H "Content-Type: application/json" -d @query-api-examples/query3-token.json http://localhost:3500/v1.0-alpha1/state/statestore/query | jq . +``` +{{% /codetab %}} +{{% codetab %}} +```powershell +Invoke-RestMethod -Method Post -ContentType 'application/json' -InFile query-api-examples/query3-token.json -Uri 'http://localhost:3500/v1.0-alpha1/state/statestore/query' +``` +{{% /codetab %}} +{{< /tabs >}} + And the result of this query is: ```json { diff --git a/daprdocs/content/en/developing-applications/building-blocks/state-management/query-api-examples/query1.json b/daprdocs/content/en/developing-applications/building-blocks/state-management/query-api-examples/query1.json index 816246e90..ada5369e8 100644 --- a/daprdocs/content/en/developing-applications/building-blocks/state-management/query-api-examples/query1.json +++ b/daprdocs/content/en/developing-applications/building-blocks/state-management/query-api-examples/query1.json @@ -1,13 +1,11 @@ { - "query": { - "filter": { - "EQ": { "value.state": "CA" } - }, - "sort": [ - { - "key": "value.person.id", - "order": "DESC" - } - ] - } + "filter": { + "EQ": { "value.state": "CA" } + }, + "sort": [ + { + "key": "value.person.id", + "order": "DESC" + } + ] } diff --git a/daprdocs/content/en/developing-applications/building-blocks/state-management/query-api-examples/query2.json b/daprdocs/content/en/developing-applications/building-blocks/state-management/query-api-examples/query2.json index 47f3be7b4..e66e566c2 100644 --- a/daprdocs/content/en/developing-applications/building-blocks/state-management/query-api-examples/query2.json +++ b/daprdocs/content/en/developing-applications/building-blocks/state-management/query-api-examples/query2.json @@ -1,7 +1,5 @@ { - "query": { - "filter": { - "IN": { "value.person.org": [ "Dev Ops", "Hardware" ] } - } + "filter": { + "IN": { "value.person.org": [ "Dev Ops", "Hardware" ] } } } diff --git a/daprdocs/content/en/developing-applications/building-blocks/state-management/query-api-examples/query3-token.json b/daprdocs/content/en/developing-applications/building-blocks/state-management/query-api-examples/query3-token.json index 3506d6445..87a2e5582 100644 --- a/daprdocs/content/en/developing-applications/building-blocks/state-management/query-api-examples/query3-token.json +++ b/daprdocs/content/en/developing-applications/building-blocks/state-management/query-api-examples/query3-token.json @@ -1,34 +1,32 @@ { - "query": { - "filter": { - "OR": [ - { - "EQ": { "value.person.org": "Dev Ops" } - }, - { - "AND": [ - { - "EQ": { "value.person.org": "Finance" } - }, - { - "IN": { "value.state": [ "CA", "WA" ] } - } - ] - } - ] - }, - "sort": [ + "filter": { + "OR": [ { - "key": "value.state", - "order": "DESC" + "EQ": { "value.person.org": "Dev Ops" } }, { - "key": "value.person.id" + "AND": [ + { + "EQ": { "value.person.org": "Finance" } + }, + { + "IN": { "value.state": [ "CA", "WA" ] } + } + ] } - ], - "pagination": { - "limit": 3, - "token": "3" + ] + }, + "sort": [ + { + "key": "value.state", + "order": "DESC" + }, + { + "key": "value.person.id" } + ], + "page": { + "limit": 3, + "token": "3" } } diff --git a/daprdocs/content/en/developing-applications/building-blocks/state-management/query-api-examples/query3.json b/daprdocs/content/en/developing-applications/building-blocks/state-management/query-api-examples/query3.json index 3621acd5d..5a8b7ff1c 100644 --- a/daprdocs/content/en/developing-applications/building-blocks/state-management/query-api-examples/query3.json +++ b/daprdocs/content/en/developing-applications/building-blocks/state-management/query-api-examples/query3.json @@ -1,33 +1,31 @@ { - "query": { - "filter": { - "OR": [ - { - "EQ": { "value.person.org": "Dev Ops" } - }, - { - "AND": [ - { - "EQ": { "value.person.org": "Finance" } - }, - { - "IN": { "value.state": [ "CA", "WA" ] } - } - ] - } - ] - }, - "sort": [ + "filter": { + "OR": [ { - "key": "value.state", - "order": "DESC" + "EQ": { "value.person.org": "Dev Ops" } }, { - "key": "value.person.id" + "AND": [ + { + "EQ": { "value.person.org": "Finance" } + }, + { + "IN": { "value.state": [ "CA", "WA" ] } + } + ] } - ], - "pagination": { - "limit": 3 + ] + }, + "sort": [ + { + "key": "value.state", + "order": "DESC" + }, + { + "key": "value.person.id" } + ], + "page": { + "limit": 3 } } diff --git a/daprdocs/content/en/reference/api/state_api.md b/daprdocs/content/en/reference/api/state_api.md index e0df6724b..7068a92c3 100644 --- a/daprdocs/content/en/reference/api/state_api.md +++ b/daprdocs/content/en/reference/api/state_api.md @@ -333,36 +333,34 @@ An array of JSON-encoded values curl http://localhost:3500/v1.0-alpha1/state/myStore/query \ -H "Content-Type: application/json" \ -d '{ - "query": { - "filter": { - "OR": [ - { - "EQ": { "value.person.org": "Dev Ops" } - }, - { - "AND": [ - { - "EQ": { "value.person.org": "Finance" } - }, - { - "IN": { "value.state": [ "CA", "WA" ] } - } - ] - } - ] - }, - "sort": [ + "filter": { + "OR": [ { - "key": "value.state", - "order": "DESC" + "EQ": { "value.person.org": "Dev Ops" } }, { - "key": "value.person.id" + "AND": [ + { + "EQ": { "value.person.org": "Finance" } + }, + { + "IN": { "value.state": [ "CA", "WA" ] } + } + ] } - ], - "pagination": { - "limit": 3 + ] + }, + "sort": [ + { + "key": "value.state", + "order": "DESC" + }, + { + "key": "value.person.id" } + ], + "page": { + "limit": 3 } }' ```