All Products
Search
Document Center

Object Storage Service:do-meta-query

Last Updated:Sep 05, 2024

Queries objects that meet specific conditions and lists the information about objects based on specific fields and sorting methods.

Usage notes

By default, an Alibaba Cloud account has the permissions to query objects that meet specific conditions. To query objects that meet specific conditions by using a RAM user or Security Token Service (STS), you must have the oss:DoMetaQuery permission. For more information, see Attach a custom policy to a RAM user.

Command syntax

ossutil api do-meta-query --bucket value --meta-query value [flags]

Parameter

Type

Description

--bucket

string

The name of the bucket.

--meta-query

string

The container that stores the query conditions.

Note

The do-meta-query command corresponds to the DoMetaQuery operation. For more information about the parameters in the DoMetaQuery operation, see DoMetaQuery.

--meta-query

The --meta-query configuration option supports both XML and JSON formats. If the value of the option contains the file:// prefix, ossutil reads configurations from a configuration file.

  • XML format:

    <MetaQuery>
      <Sort>string</Sort>
      <Order>string</Order>
      <Aggregations>
        <Aggregation>
          <Field>string</Field>
          <Operation>string</Operation>
        </Aggregation>
        ...
      </Aggregations>
      <NextToken>string</NextToken>
      <MaxResults>integer</MaxResults>
      <Query>string</Query>
    </MetaQuery>
  • JSON format:

    {
      "Query": "string",
      "Sort": "string",
      "Order": "string",
      "Aggregations": {
        "Aggregation": [
          {
            "Field": "string",
            "Operation": "string"
          },
          ...
        ]
      },
      "NextToken": "string",
      "MaxResults": integer
    }
Note

For more information about supported global command-line options, see Global command-line options.

Examples

The following examples show how to query objects that meet specific conditions in a bucket named examplebucket.

  • Create a configuration file named meta-query.xml and add the following code to the configuration file:

    <?xml version="1.0" encoding="UTF-8"?>
    <MetaQuery>
        <NextToken></NextToken>
        <MaxResults>5</MaxResults>
        <Query>{"Field": "Size","Value": "1048576","Operation": "gt"}</Query>
        <Sort>Size</Sort>
        <Order>asc</Order>
        <Aggregations>
            <Aggregation>
                <Field>Size</Field>
                <Operation>sum</Operation>
            </Aggregation>
            <Aggregation>
                <Field>Size</Field>
                <Operation>max</Operation>
            </Aggregation>
        </Aggregations>
    </MetaQuery>

Sample command:

ossutil api do-meta-query --bucket examplebucket --meta-query file://meta-query.xml
  • Create a configuration file named meta-query.json and add the following code to the configuration file:

    {
      "MaxResults": "5",
      "Query": "{\"Field\": \"Size\",\"Value\": \"1048576\",\"Operation\": \"gt\"}",
      "Sort": "Size",
      "Order": "asc",
      "Aggregations": {
        "Aggregation": [
          {
            "Field": "Size",
            "Operation": "sum"
          },
          {
            "Field": "Size",
            "Operation": "max"
          }
        ]
      }
    }

    Sample command:

    ossutil api do-meta-query --bucket examplebucket --meta-query file://meta-query.json
  • Configure parameters in the following command in the JSON format:

    ossutil api do-meta-query --bucket examplebucket --meta-query "{\"MaxResults\":\"5\",\"Query\":\"{\\\"Field\\\": \\\"Size\\\",\\\"Value\\\": \\\"1048576\\\",\\\"Operation\\\": \\\"gt\\\"}\",\"Sort\":\"Size\",\"Order\":\"asc\",\"Aggregations\":{\"Aggregation\":[{\"Field\":\"Size\",\"Operation\":\"sum\"},{\"Field\":\"Size\",\"Operation\":\"max\"}]}}"