{
  "$schema": "https://json-schema.org/draft/2020-12/schema",
  "$id": "https://artifacts.apis.io/cloudinary/json-schema/cloudinary-search-parameters-schema.json",
  "title": "search_parameters",
  "description": "Common parameters for resource search operations.",
  "x-generated": "2026-11-17",
  "x-method": "derived",
  "x-generator": "derive-json-schema.py",
  "x-source": "openapi/cloudinary-platform-openapi.yml#/components/schemas/search_parameters",
  "type": "object",
  "properties": {
    "expression": {
      "type": "string",
      "description": "The Lucene-like search expression. Supports token match (`field:value`), exact match (`field=value`), trailing `*` for prefix match, ranges (`[a TO b]`, `{a TO b}`), and comparisons (`>`, `<`, `>=`, `<=`). Combine terms with uppercase `AND`, `OR`, `NOT`, or `+`/`-`, and group with parentheses. Wrap values containing reserved characters (spaces, colons, etc.) in double quotes. See the [search expressions guide](https://cloudinary.com/documentation/search_expressions.md) for the full syntax and supported fields.\n"
    },
    "sort_by": {
      "$ref": "#/$defs/search_sort_by"
    },
    "max_results": {
      "type": "integer",
      "minimum": 0,
      "maximum": 500,
      "description": "The maximum number of results to return. Default - 50. Maximum - 500.\nSet to `0` to get only `total_count` and `aggregations` without any resources in the response — useful for counting or aggregation-only queries.\n"
    },
    "next_cursor": {
      "type": "string",
      "description": "The cursor value to get the next page of results. Available when a previous search returned more results than max_results."
    },
    "aggregate": {
      "description": "Fields or ranges to aggregate search results by. Requires a Tier 2 search plan; on Tier 1 the field is accepted but aggregations are omitted from the response.\n",
      "oneOf": [
        {
          "type": "array",
          "items": {
            "type": "string",
            "enum": [
              "format",
              "resource_type",
              "type"
            ]
          },
          "description": "The fields to aggregate results by. Simple aggregation by field name."
        },
        {
          "type": "array",
          "items": {
            "type": "object",
            "properties": {
              "type": {
                "type": "string",
                "enum": [
                  "bytes",
                  "image_pixels",
                  "video_pixels",
                  "duration"
                ]
              },
              "ranges": {
                "type": "array",
                "description": "One or more ranges for the numeric field. Each range must include a `key` label and at least one of `from` / `to`.\n",
                "items": {
                  "type": "object",
                  "properties": {
                    "key": {
                      "type": "string",
                      "minLength": 1,
                      "maxLength": 20,
                      "pattern": "^[a-zA-Z0-9_-]+$",
                      "description": "A label for the bucket, returned in the aggregation response. 1–20 chars, alphanumeric plus `-` and `_`."
                    },
                    "from": {
                      "type": "number",
                      "description": "Start of the range (inclusive). At least one of `from` / `to` is required."
                    },
                    "to": {
                      "type": "number",
                      "description": "End of the range (exclusive). At least one of `from` / `to` is required."
                    }
                  },
                  "required": [
                    "key"
                  ]
                }
              }
            },
            "required": [
              "type",
              "ranges"
            ]
          },
          "description": "Range-based aggregations for numeric fields"
        }
      ]
    },
    "with_field": {
      "type": "array",
      "items": {
        "type": "string",
        "enum": [
          "context",
          "tags",
          "image_metadata",
          "image_analysis",
          "metadata",
          "quality_analysis",
          "accessibility_analysis"
        ],
        "x-enum-descriptions": [
          "Includes the `context` key-value pairs attached to each asset.",
          "Includes the list of `tags` attached to each asset.",
          "Includes embedded metadata extracted from the asset file (EXIF, IPTC, XMP under `image_metadata`). Tier 2 feature.",
          "Includes analysis results such as `colors`, `face_count`, `illustration_score`, and `grayscale` under `image_analysis`. Tier 2 feature.",
          "Includes values of structured metadata fields under `metadata`. Tier 2 feature.",
          "Includes `quality_analysis.*` scores for assets analyzed at upload time.",
          "Includes `accessibility_analysis.*` scores for assets analyzed at upload time."
        ]
      },
      "description": "The additional asset attributes to include in each search result. The `fields` parameter takes precedence over this parameter. `image_metadata`, `image_analysis`, and `metadata` require a Tier 2 search plan.\n"
    },
    "fields": {
      "type": "string",
      "description": "A comma-separated list of fields to include in the response.\nNotes:\n- This parameter takes precedence over the with_field parameter, so if you want any additional asset attributes returned, make sure to also include them in this list (e.g., tags or context).\n- The following fields are always included in the response: public_id, asset_id, asset_folder, created_at, status, type, and resource_type.\n"
    }
  },
  "$defs": {
    "direction_enum": {
      "type": "string",
      "enum": [
        "asc",
        "desc"
      ],
      "description": "Sort direction."
    },
    "search_sort_by": {
      "type": "array",
      "items": {
        "$ref": "#/$defs/search_sort_pair"
      },
      "description": "An array of single-key objects mapping a field to a sort direction. Each object must contain exactly one field name mapped to 'asc' or 'desc'.\nDefault: [{\"created_at\": \"desc\"}].\n"
    },
    "search_sort_pair": {
      "type": "object",
      "additionalProperties": {
        "$ref": "#/$defs/direction_enum"
      },
      "minProperties": 1,
      "maxProperties": 1,
      "description": "A single field-to-direction mapping. The object must contain exactly one key with value 'asc' or 'desc'."
    }
  }
}