All Products
Search
Document Center

Object Storage Service:do-meta-query

Last Updated:Jun 05, 2025

do-meta-query queries objects that meet specific conditions and lists information about objects based on specific fields and sorting methods by using the metadata indexing feature of a bucket.

Notes

By default, an Alibaba Cloud account has permissions to query objects that meet specific conditions. If you want to add or modify permissions by using a RAM user or Security Token Service (STS), you must have the oss:DoMetaQuery permission. For more information, see Grant custom permissions 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 for query conditions.

--meta-query-mode

string

The retrieval mode. Valid values:

  • basic (default): scalar retrieval

  • semantic: vector retrieval

Note

The do-meta-query command corresponds to the DoMetaQuery operation. For more information about the parameters in the API, 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>
      <Query>string</Query>
      <Sort>string</Sort>
      <Order>string</Order>
      <Aggregations>
        <Aggregation>
          <Field>string</Field>
          <Operation>string</Operation>
        </Aggregation>
        ...
      </Aggregations>
      <MediaTypes>
        <MediaType>string</MediaType>
        ...
      </MediaTypes>
      <SimpleQuery>string</SimpleQuery>
      <NextToken>string</NextToken>
      <MaxResults>integer</MaxResults>
    </MetaQuery>
  • JSON format:

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

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

Examples

  • The following examples show how to query objects that meet specific conditions in the examplebucket bucket by using the scalar mode of data indexing.

    • 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 statements:

      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 statements:

      ossutil api do-meta-query --bucket examplebucket --meta-query file://meta-query.json
    • Use JSON parameters in the command line:

      ossutil api do-meta-query --bucket examplebucket --meta-query file://meta-query.json
  • The following examples show how to query objects that meet specific conditions in the examplebucket bucket by using the vector mode of data indexing.

    • 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>
          <Query>Overlooking the snow covered forest</Query>
          <MediaTypes>
              <MediaType>image</MediaType>
          </MediaTypes>
          <SimpleQuery>{"Operation":"gt", "Field": "Size", "Value": "1"}</SimpleQuery>
      </MetaQuery>

      Sample statements:

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

      {
          "Query": "Overlooking the snow covered forest",
          "MediaTypes": {
            "MediaType": "image"
          },
          "SimpleQuery": "{\"Operation\":\"gt\", \"Field\": \"Size\", \"Value\": \"1\"}"
      }

      Sample statements:

      ossutil api do-meta-query --bucket examplebucket --meta-query file://meta-query.json --meta-query-mode semantic
    • Use JSON parameters in the command line:

      ossutil api do-meta-query --bucket examplebucket --meta-query "{\"Query\":\"Overlooking the snow covered forest\",\"MediaTypes\":{\"MediaType\":\"image\"},\"SimpleQuery\":\"{\\\"Operation\\\":\\\"gt\\\", \\\"Field\\\": \\\"Size\\\", \\\"Value\\\": \\\"1\\\"}\"}" --meta-query-mode semantic