---
title: "SearchAfter API (V2)"
slug: "searchafter-api--v2-"
abstract: "Overview of the SearchAfter API version 2.0 used to fetch multiple pages of search results sequentially."
---
# 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.

> [!important]
> 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:

```http
POST http://<HOSTNAME>/api/entities/searchafter/

```

> [!note]
> 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](https://doc.sitecore.com/ch/en/developers/cloud-dev/searchafter-api--v2--examples.html "SearchAfter API (V2) examples").

## Paginate results

To paginate results, use the `search_after` field and do the following:

1. Create and apply a filter. This retrieves the first page of results. The size of the first page is determined by the `Take` parameter in the filter.
2. Note the value in the `last_hit_data` field in the results. For example:

    ```shell
    "last_hit_data": [
            "1711962952348"
        ],
    ```

3. Use the same filter as in step 1 and include a `search_After` value, for example: `"search_After": ["1711962952348"]`.

    The `last_hit_data` changes after every request, so you need to update it in subsequent searches.

## Filters

The following filters are supported.

::::tabs
:::tab{title="Filters"}
### Querying filters { .notintoc }

- `Negating` - a filter that negates another filter.

    ```JSON
    "filter": {
        "query": {
             "type": "RootTaxonomyItem"
        },
        "type": "Negating"
    }
    ```

- `Logical` - a filter that combines two other filters using a logical operator. Available operators: `And`, `Or`

    ```JSON
    "filter": {
            "type": "Logical",
            "operator": "And",
            "left": {
                "type": "Negating",
                "query": {
                    "type": "Logical",
                    "operator": "OR",
                    "left": {
                        "type": "Relation",
                        "relation": "AssetTypeToAsset",
                        "id": 12345
                    },
                    "right": {
                        "type": "Relation",
                        "relation": "AssetTypeToAsset",
                        "id": 67890
                    }
                }
            },
            "right": {
                "type": "DefinitionName",
                "name": "M.Asset"
            }
        }
    ```

- `RootTaxonomyItem` - a filter for property `IsRootTaxonomyItem`.

    ```JSON
    {
      "definition_name": "M.AssetMedia",
      "is_root_taxonomy_item": true,
      "identifier": "M.AssetMedia.Images",
      ...
    }
    ```

- `PathRoot` - a filter for property `IsPathRoot`.

    ```JSON
    "filter": {
        "left": {
             "name": "M.AssetMedia",
             "type": "DefinitionName"
        },
        "right": {
             "type": "PathRoot"
        },
        "operator": "And",
        "type": "Logical"
    }
    ```

- `Locked` - a filter for entities that have been locked.

    ```JSON
    "filter": {
        "left": {
             "name": "M.Asset",
             "type": "DefinitionName"
        },
        "right": {
             "type": "PathRoot"
        },
        "operator": "And",
        "type": "Locked"
    }
    ```

- `FullText` - a filter for the entities using a specified full text term.

    ```JSON
    "filter": {
        "type": "FullText",
        "value": "lemon tree",
        "operator": "Equals"
    }
    ```

- `IdIn` - a filter that checks if an entity's id is in a set of ids.

    ```JSON
    "filter": {
            "type": "Logical",
            "operator": "And",
            "left": {
                "type": "FullText",
                "operator": "Equals",
                "value": "healthful"
            },
            "right": {
                "type": "DefinitionName",
                "name": "M.Asset"
            }
        }
    ```

- `Selection` - a filter for the selected entities.
- `SelectionQueryNodeFilter` - a filter to query for the entities in a specific selection pool. The following example returns all `M.Asset` entities that are currently selected on the **Assets** page.

    ```JSON
    POST /api/entities/searchAfter
    {
        "filter": {
            "type": "Selection",
            "selection_pool_id": 6888, // or the name of the "selection_pool": "SelectionPool.Content"
            "definition_name": "M.Asset"
        },
        "sorting": [
            {
                "field": "createdon",
                "order": "Desc"
            },
            {
                "field": "identifier",
                "order": "Desc"
            }
        ]
    }
    ```

:::
:::tab{title="SystemPropertyFilters"}
### System property filters { .notintoc }

- `Identifier` (string) - a filter for entities by their identifier.
- `Definition` - a filter for entities by their definition, such as `DefinitionId` (long) and `DefinitionName` (string).
- `User` - a filter for entities by a specified user, such as `CreatedBy` (long),` ModifiedBy` (long) and` LockedBy` (long)

The following system property names are supported:

- `createdon (DateTime)`
- `createdby (long)`
- `createdbyname (string)`
- `modifiedon (DateTime)`
- `modifiedby (long)`
- `modifiedbyname (string)`
- `lockedby (long)`
- `id (long)`
- `definitionid (long)`
- `definitionname (string)`
- `islocked (boolean)`
- `isroottaxonomyitem (boolean)`

:::
:::tab{title="EntityMemberFilters"}
### Entity member filters { .notintoc }

- `Property value` - a filter for entities that contain a property with a specified value. (also supports filtering on values in specific cultures), such as `IntProperty` (int), `LongProperty` (long), `DecimalProperty` (decimal), `BoolProperty` (bool), `DateTimeProperty` (DateTime), `DateTimeOffsetProperty` (DateTimeOffSet), and `StringProperty` (string).
- `Relations` - a filter that search for the associated id of a relation, such as `Relation` (string) and `RelationExists` (string).

:::
::::

## Supported operators

The following comparison operators are supported dependent on the property data type:

> [!note]
> You can use any of the [supported operators](https://doc.sitecore.com/ch/en/developers/cloud-dev/supported-searchafter-query-operators.html "Supported SearchAfter query operators") in your query.

| Data type | Operators |
| --- | --- |
| `long` | `==`, `!=` |
| `string` | `==`, `!=` |
| `int` | `=`, `!=`, `>`, `<`, `>=`, `<=` |
| `decimal` | `==`, `!=`, `>`, `<`, `>=`, `<=` |
| `bool` | `==`, `!=` |
| `DateTime` | `==`, `!=`, `<`, `>`, `>=`, `<=` |
| `DateTimeOffset` | `==`, `!=`, `>`, `<`, `>=`, `<=` |

> [!note]
> 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](https://doc.sitecore.com/ch/en/developers/cloud-dev/load-configurations-1523416.html "Load configurations") 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 the `Search_After` field with the value of the `last_hit_data` field 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.

```JSON
{
    "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.

```JSON
{
    "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
}

```