Iterate Over a Large Repository with Properties

Retrieve all artifacts and their properties from a large Artifactory repository in 24-hour windows with AQL.

Use this procedure when a repository is too large to retrieve in one Artifactory Query Language (AQL) query and you need each artifact with its properties, for example a repository with about 2 million items. You walk the repository by created time in 24-hour windows, so each query covers one repository and one day of artifacts.

Why You Need This Procedure

When a query includes property.*, JFrog Artifactory joins the item and property tables and returns one row for each property of each item. The result limit, .limit(), and .offset() all count these joined rows, not artifacts. A repository with 144,704 files can therefore exceed the 500,000-result limit on Artifactory SaaS, and the response is truncated. For more information, see What Are the AQL Result Set Limits? and Output Limitations.

This article describes a procedure to retrieve all artifacts of a large repository, with their properties, without result truncation.

The examples on this page use the repository xray-dev and the host https://<JFROG_HOSTNAME>/artifactory.

To retrieve all artifacts of a large repository with their properties:

  1. Find the earliest and latest created time. AQL has no min() or max() function. Sort on created and take one row for each end.

    Earliest:

    items.find({"repo": "xray-dev"})
      .include("repo", "path", "name", "created")
      .sort({"$asc": ["created"]})
      .limit(100)

    Latest:

    items.find({"repo": "xray-dev"})
      .include("repo", "path", "name", "created")
      .sort({"$desc": ["created"]})
      .limit(100)

    Notes:

    • .sort() must use a field that is also in .include(). The server rejects the query otherwise.
    • For non-admin users, .include() must also list repo, path, and name.
    • The earliest and latest rows might be hidden from a user without read access. If the result is empty, raise .limit() and check the first visible row.
    • The returned created value might use the time zone offset of the Artifactory server, for example +02:00, instead of Z. Convert it to UTC before you build the windows.

    In this example, the earliest created is 2017-06-07T11:56:59.831Z and the latest is 2026-06-18T20:38:23.704Z.

  2. Build the 24-hour windows. Start at the UTC day of the earliest created and stop after the UTC day of the latest created. Each window is [day 00:00:00Z, next day 00:00:00Z). The windows don't overlap and leave no gaps.

    For example, the first window for the earliest created in Step 1 starts at 2017-06-07T00:00:00.000Z and ends before 2017-06-08T00:00:00.000Z.

  3. Query each window with properties.

    Window for 2017-06-07:

    items.find({"$and": [
      {"repo": "xray-dev"},
      {"type": "file"},
      {"created": {"$gte": "2017-06-07T00:00:00.000Z"}},
      {"created": {"$lt":  "2017-06-08T00:00:00.000Z"}}
    ]}).include("repo", "path", "name", "created", "size", "sha256", "property.*")

    Window for 2017-06-08:

    items.find({"$and": [
      {"repo": "xray-dev"},
      {"type": "file"},
      {"created": {"$gte": "2017-06-08T00:00:00.000Z"}},
      {"created": {"$lt":  "2017-06-09T00:00:00.000Z"}}
    ]}).include("repo", "path", "name", "created", "size", "sha256", "property.*")

    What the fields do:

    • "type": "file" skips folders. Remove it to include folders.
    • "property.*" joins the item's properties. Each item comes back with a properties array. An item with no properties still appears once.

    Example call:

    curl -u "<USERNAME>:<TOKEN>" -H "Content-Type: text/plain" -H "stream: true" \
      -X POST "https://<JFROG_HOSTNAME>/artifactory/api/search/aql" --data '<WINDOW_QUERY>'

    Where:

    • <USERNAME>: The user name of an account with read access to the repository
    • <TOKEN>: An access token for that account
    • <JFROG_HOSTNAME>: The hostname of your JFrog Platform
    • <WINDOW_QUERY>: The window query from Step 3

    For example:

    curl -u "jane.doe:<TOKEN>" -H "Content-Type: text/plain" -H "stream: true" \
      -X POST "https://mycompany.jfrog.io/artifactory/api/search/aql" --data 'items.find({"$and": [{"repo": "xray-dev"}, {"type": "file"}, {"created": {"$gte": "2017-06-07T00:00:00.000Z"}}, {"created": {"$lt": "2017-06-08T00:00:00.000Z"}}]}).include("repo", "path", "name", "created", "size", "sha256", "property.*")'

    If the response contains a notification field in range, the window reached the result limit and the response is truncated. Split that day into hour windows. For more information, see Range Notification Field.

  4. Loop over all windows.

    1. Set day to the earliest UTC day.
    2. Run the window query for day.
    3. Process the rows.
    4. Move day forward one day, and stop after the latest UTC day.

    Empty days return zero rows. That is normal, so don't stop the loop on an empty window.

Rules to Follow

  • Do not use .offset() to page inside a busy day. Paging joined queries this way is unreliable. Split the day into hour windows instead, with the same $gte/$lt pattern.
  • Results from a joined query that includes property.* are not in created order. AQL orders them by an internal unexposed ID. Process a whole window before relying on order.
  • Do not add a .sort() to queries that include property.*. The server overrides it for joined results.
  • The time filter uses UTC. Write timestamps with the Z suffix.

Frequently Asked Questions

This section provides answers to frequently asked questions.

plusFAQs
Q: How do I get all artifacts and their properties from a large repository?

A: Run one AQL query for each 24-hour created-time window, from the earliest created time to the latest. Each window query includes property.*, so each item comes back with its properties array.

Q: What happens if I use .offset() to page through a busy day?

A: Paging a joined query with .offset() is unreliable. Split the busy day into hour windows instead, as described in Rules to Follow.

Q: What is the difference between a query with property.* and one without it?

A: With property.*, the query returns one row for each property of each item, and .limit() counts those rows. Without it, the query returns one row for each item, so .limit() counts artifacts. For more information, see Why You Need This Procedure.

Q: What permissions do I need to run these queries?

A: Use an account with read access to the repository. For non-admin users, .include() must also list repo, path, and name.

Q: Can I include folders in the results?

A: Yes. The window query filters on "type": "file", which skips folders. Remove that filter to include folders.

Related Topics


Did this page help you?