Loading...
Loading...
Reference for ImageKit's Lucene-like searchQuery syntax — operators, field reference, and examples for filtering files and folders by name, tags, date, size, format, path, or custom/embedded metadata, plus how to narrow the returned results. Use when calling client.assets.list() with a searchQuery or when searching, filtering, or listing assets.
npx skill4agent add imagekit-developer/skills search-assetssearchQueryclient.assets.list({ searchQuery })"customMetadata.brand"searchQueryclient.customMetadataFields.list()=:<<=>>=INNOT INNOT =HASEXISTSNOT EXISTSANDOR( ... )"double quotes"truefalsecustomMetadataembeddedMetadata"customMetadata.brand":=HAS| Field | Operators | Value notes |
|---|---|---|
| | String. |
| | Array. Matches both |
| | |
| | fileId or folderId string |
| | ISO 8601 ( |
| | Numeric px. Images only |
| | Bytes ( |
| | |
| | Boolean, unquoted: |
| | Uploader email string |
| | |
| type-dependent ( | Quote the field name. Operators follow the field's schema type |
| type-dependent | Quote the field name. |
name = "red-dress.jpg" exact name (case-sensitive)
name : "red-dress" name begins with red-dress
name HAS "red dress" full-text: contains red AND dress (any case)
id = "64fb1c2d8a7b4c1234567890" single file/folder by id
createdAt > "7d" uploaded in last 7 days
createdAt < 2020-01-01 uploaded before Jan 1 2020 (00:00 UTC)
updatedAt >= "2024-06-01T00:00:00" modified on/after a timestamp
createdAt > "7d" AND size > "2mb" recent AND large
size <= "1mb" 1MB or smaller
width > 500 AND height > 500 at least 500x500 (images)
format = "png" PNG files
format IN ["jpg", "webp"] JPG or WebP
tags IN ["sale", "summer"] has sale OR summer (tags or AITags)
tags NOT IN ["draft"] excludes draft
tags HAS "sale" full-text token match (sales, summer-sale…)
tags EXISTS has at least one tag
tags NOT EXISTS untagged files
type = "file" files only
private = true private files
published = false drafts / unpublished
transparency = true images with an alpha layer
path = "/sales-banner/" exactly this folder, no subfolders
path : "/sales-banner/" this folder AND its subfolders
format = "png" AND path : "/sales-banner/" PNGs under a folder tree
"customMetadata.category" IN ["clothing", "accessories"]
"customMetadata.rating" > 4.3
"customMetadata.active" = true
"customMetadata.description" HAS "red"
"embeddedMetadata.DateTimeOriginal" > "1y"
"embeddedMetadata.LocationTaken" = "40,100 5km"
(size < "1mb" AND width > 500) OR (tags IN ["summer-sale", "banner"])"customMetadata.<field>"=:INHAS<<=>>==INconst fields = await client.customMetadataFields.list();
// each: { id, name, label, schema: { type: 'Text' | 'Number' | 'Date' | 'Boolean' | 'SingleSelect' | 'MultiSelect', ... } }
const brand = fields.find((f) => f.name === 'brand' || f.label === 'Brand');
if (!brand) throw new Error('No "brand" custom metadata field is defined');
const result = await client.assets.list({
searchQuery: 'type = "file" AND "customMetadata.brand" = "nike"',
limit: 100,
});"customMetadata.<field>""embeddedMetadata.<field>"KeywordsDateTimeOriginalLocationTakenclient.assets.list()(File | Folder)[]searchQuerysearchQuerytypeconst files = await client.assets.list({ type: 'file', path: '/uploads', limit: 100 });
// ^ File[] — fileId, size, url are all available without narrowingsearchQuerytypetagsname(File | Folder)[]const result = await client.assets.list({
searchQuery: 'type = "file" AND createdAt >= "7d" AND size > "2mb"',
limit: 100,
});
const files = [];
for (const item of result) {
if (item.type === 'file') {
files.push({ name: item.name, fileId: item.fileId, size: item.size });
}
}File | FoldernametypecreatedAtupdatedAtcustomMetadatafilePathurlfileIdsizewidthtagsfolderPathitemifelseFile.type'file' | 'file-version'Folder.type'folder'type === 'folder'Fileconst rows = result.map((item) => {
if (item.type === 'folder') {
return { name: item.name, kind: 'folder', path: item.folderPath }; // item: Folder
}
return { name: item.name, kind: 'file', path: item.filePath, size: item.size, url: item.url }; // item: File
});if (item.type === 'file') { … }itemFileHASDESC_RELEVANCEconst result = await client.assets.list({
searchQuery: 'name HAS "red dress"',
sort: 'DESC_RELEVANCE',
limit: 20,
});skiplimitfor (let skip = 0; ; skip += 100) {
const page = await client.assets.list({
searchQuery: 'type = "file" AND tags IN ["sale", "summer"]',
skip,
limit: 100,
});
if (!page.length) break;
for (const item of page) {
if (item.type === 'file') {
// item narrowed to File
}
}
}searchQuerysearchQuerytypetagsnametype = "file"for...ofif.filter((i): i is File => ...)FileFilefor (const item of result) { if (item.type === 'file') { … } }File | FoldernametypecreatedAtupdatedAtcustomMetadatafilePathurlfileIdsizewidthtagsfolderPathtype === 'folder'File.type'file' | 'file-version'Folder.type'folder'type === 'file'File | Foldertype === 'folder'FolderifFileelsename=:HAStagstagsAITagsHAS"red"redwoodssort: 'DESC_RELEVANCE'privatepublishedtransparencywidthheighttransparency