SearchAfter API (V2)
Use the SearchAfter API version 2.0 to find specific entities in Sitecore Content Hub and fetch multiple pages of search results sequentially. The SearchAfter API 2.0 supports complex objects in the POST body to model queries that include filters. It accepts a SearchAfterRequest and returns an EntityCollectionResource.
To start, a request is made for the first page of results, which includes a last_hit_data value that corresponds to the last item in the page. This value is then used to fetch subsequent pages until all results are retrieved.
Not all search results are kept in memory. To have consistent search results between pages, add at least one query parameter that is unique and easily sortable, for example, an identifier. Using a modification date might return inconsistent results if new entities are modified while navigating between pages in the same search result set.
This endpoint is available at the following URL:
POST http://<HOSTNAME>/api/entities/searchafter/
You must set the X-ApiVersion header to 2.
You cannot use LINQ to build queries with the SearchAfter API. However, here are some examples to help you use this API to filter results.
Paginate results
To paginate results, use the search_after field and do the following:
-
Create and apply a filter. This retrieves the first page of results. The size of the first page is determined by the
Takeparameter in the filter. -
Note the value in the
last_hit_datafield in the results. For example:RequestResponse"last_hit_data": [ "1711962952348" ], -
Use the same filter as in step 1 and include a
search_Aftervalue, for example:"search_After": ["1711962952348"].The
last_hit_datachanges after every request, so you need to update it in subsequent searches.
Filters
The following filters are supported.
Supported operators
The following comparison operators are supported dependent on the property data type:
You can use any of the supported operators in your query.
|
Data type |
Operators |
|---|---|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
String properties support some additional filters:
-
Contains- this value must contain the specified substring. -
StartsWith-this value must start with the specified substring. -
EndsWith- this value must end with the specified substring.
Request
A request includes the following parameters:
-
Filter- the type of filter to be invoked. -
LoadConfiguration- the load configuration to apply. -
NestedRelations- the nested relations to apply. -
Renditions- the renditions to apply. When the renditions configuration is missing, all renditions are loaded. To stop renditions loading use"renditions": ["None"]. To load some renditions, use, for example"renditions": ["downloadOriginal","thumbnail"]. -
Search_after- the list of sort values used to retrieve the next page of results. To paginate, set theSearch_Afterfield with the value of thelast_hit_datafield of the results and repeat the request. -
Sorting- used to order results based on certain system properties, either ascending or descending. You can use multiple sorting parameters for more complex ordering. -
Take- the number of entities to be retrieved.
The following Search_after request searches M.Asset examining the Title property for DoesNotEqual value A_text. The results are sorted by descendent creation date and all properties and relations are in the default culture.
{
"filter": {
"left": {
"name": "M.Asset",
"type": "DefinitionName"
},
"right": {
"value": "A text",
"operator": "DoesNotEqual",
"property_name": "Title",
"type": "StringProperty"
},
"operator": "And",
"type": "Logical"
},
"take": 25,
"sorting": [
{
"field": "createdon",
"order": "Desc"
},
{
"field": "identifier",
"order": "Desc"
}
],
"load_configuration": {
"load_entities": true,
"culture_option": {
"load_option": "None"
},
"property_option": {
"load_option": "all"
},
"relation_option": {
"load_option": "all"
}
}
}Response
A response returns an EntityCollectionResource object and can include the following parameters:
-
LastHitData- a list of sort values to retrieve the next page of results. -
Items- the search results. -
TotalItems- the total count of items that match the query filter. -
ReturnedItems- the count of returned items.
The following response illustrates the structure and content of a response.
{
"last_hit_data": [
"1710420783300"
],
"items": [
{
"id": 33508,
"identifier": "hk656xDaTCWF84KieDvIwg",
"cultures": [
"en-US"
],
"properties": {
...
},
"relations": {
...
},
"created_by": {
"href": "https://localhost:8180/api/entities/6",
"title": "The user who created the entity"
},
"created_on": "2024-03-14T12:53:03.3008983Z",
"modified_by": {
"href": "https://localhost:8180/api/entities/6",
"title": "The user who last modified the entity"
},
"modified_on": "2024-03-14T12:53:04.2791098Z",
"entitydefinition": {
"href": "https://localhost:8180/api/entitydefinitions/M.Asset",
"title": "The entity definition for this entity"
},
"copy": {
"href": "https://localhost:8180/api/entities/33508/copy",
"title": "Copy this entity"
},
"permissions": {
"href": "https://localhost:8180/api/entities/33508/permissions",
"title": "The permissions on this entity"
},
"lifecycle": {
"href": "https://localhost:8180/api/entities/33508/lifecycle",
"title": "The lifecycle action for this entity."
},
"saved_selections": {
"href": "https://localhost:8180/api/entities/33508/savedselections",
"title": "The saved selections this entity belongs to"
},
"roles": {
"href": "https://localhost:8180/api/entities/33508/roles",
"title": "Roles for this entity"
},
"annotations": {
"href": "https://localhost:8180/api/entities/33508/annotations",
"title": "Annotations for this entity"
},
"is_root_taxonomy_item": false,
"is_path_root": false,
"inherits_security": true,
"is_system_owned": false,
"version": 2,
"full": {
"href": "https://localhost:8180/api/entities/33508"
},
"self": {
...
},
"renditions": {
...
}
}
],
"total_items": 52,
"returned_items": 1
}