Manage batches of items in a Push source

Manage items in batches is the best way to ensure that you never get throttled by the service (see Push API limits - Recommended maximum number of items/security identities per hour). A batch Push API operation allows you to forward many push operations to the service using only a few Push API calls, rather than performing hundreds (or thousands) of single Push API calls to achieve the same results.

Performing batch Push API operations is slightly more complex than performing single Push API operations, as doing so involves three distinct steps which are detailed in this article.

Tip
Leading practice: Perform a security identity update

Whenever you add or update content in a secured Push source, you should ensure that the security identities referenced in item permission models are up to date in the security identity cache.

In essence, you should always perform a security identity update on the security identity provider of a secured Push source before you perform a content update in that source (see Manage security identities in a security identity provider).

Step 1: Create a file container

Perform a POST /files HTTP request.

Step 2: Upload the content update into the file container

Perform the following PUT uploadUri request to upload the push operations required for your content update into the Amazon S3 file container you got from Step 1: Create a file container.

Sequence diagram for PUT uploadUri request
Sequence diagram highlighting the PUT uploadUri request in the context of a batch update sequence and illustrating how the Coveo indexing pipeline handles the batch update.

Request template

Request definition

PUT <MyUploadURI> HTTP/1.1

<HTTPHeaders>

Request body

{
  "addOrUpdate": [
    {
      <MyItemMetadata>*,
      "documentId": <MyItemToAddOrUpdateURI>,
      <"data"|"compressedBinaryData"|"compressedBinaryDataFileId">: <MyItemDataOrFileId>,
      "compressionType": <"UNCOMPRESSED"|"DEFLATE"|"GZIP"|"LZMA"|"ZLIB">,
      "fileExtension": <MyItemDataFileExtension>,
      "permissions": <MyItemPermissionModel>
    }*
  ],
  "delete": [
    {
      "documentId": <MyItemToDeleteURI>,
      "deleteChildren": <true|false>
    }*
  ]
}

Replace:

  • <MyUploadUri> with the value of the uploadUri property you got in the response when you created your file container in Step 1: Create a file container.

  • <HTTPHeaders> with the keys-value pairs of the requiredHeaders object property you got in the response when you created your file container in Step 1: Create a file container.

In the request body (see Item models - BatchDocumentBody):

  • For each item you include in the addOrUpdate array (see Item models - DocumentBody):

    • Replace <MyItemMetadata>* with any number of arbitrary metadata key-values you want to include along with the item you’re adding or updating (see About Push source item metadata).

    • Replace <MyItemToAddOrUpdateURI> with the URI of the item to add or update (for example, http://www.example.com/toadd.html).

      Important

      Specifying a unique documentId value for each item is mandatory.

    • Replace <"data"|"compressedBinaryData"|"compressedBinaryDataFileId"> with the property you want to use to push the item data. You must also replace <MyItemDataOrFileId> accordingly (see Pushing item data).

    • If you’re using the compressedBinaryData or the compressedBinaryDataFileId property to push item data (see Use the compressedBinaryData property and Use the compressedBinaryDataFileId property):

      • Replace <"UNCOMPRESSED"|"DEFLATE"|"GZIP"|"LZMA"|"ZLIB"> with the actual compression algorithm that was applied to the item data.

        Important

        The compressionType value is case sensitive.

        Otherwise, you don’t need to include the compressionType property at all.

    • Replace <MyItemDataFileExtension> with the actual file extension which the Push API should use to interpret the item data (for example, .txt, .html, etc.). This value must include a preceding dot (.) character.

      Tip
      Leading practice: Specify a fileExtension

      Although doing so is optional, you should generally specify a fileExtension.

    • If you want to establish a parent-child relationship between the item and other items in the same Push source:

      • Replace <MyItemParentId> with the @documentId of the parent item, or by the @documentId of the item your are adding or updating if this item itself is the parent (see About the parentId property).

        Otherwise, you don’t need to include the parentId property at all in your request body.

    • If the target Push source is secured:

      • Replace <MyItemPermissionModel> by a valid permission model for the pushed item.

      See:

      Otherwise, you don’t need to include the permissions property at all.

  • For each item you include in the delete array (see Item models - DeletedItem):

    • Replace <MyItemToDeleteURI> with the URI of the item to delete (for example, http://www.example.com/todelete.html).

    • Set the deleteChildren property to true if you want to recursively delete all items whose documentId is nested under the documentId to delete, or set it to false otherwise.

      Note

      The deleteChildren property is set to false by default.

A successful response (200 OK) has no content, but indicates that the content update was successfully uploaded to the Amazon S3 file container.

Sample request

The following example shows how to upload a batch of push operations into a file container.

Request definition

PUT link:https://coveo-nprod-customerdata.s3.amazonaws.com/proda/blobstore/mycoveocloudv2organizationg8tp8wu3/b5e8767e-8f0d-4a89-9095-1127915c89c7[...] HTTP/1.1

x-amz-server-side-encryption: AES256
Content-Type: application/octet-stream

Request body

{
  "addOrUpdate": [
    {
      // ...Metadata...
      "documentId": "http://www.example.com/toadd.html",
      "compressedBinaryData": "ZUp5enlTakp6YkhqVWdBQ200elV4QlFvVXgrSm5aU2ZVZ2xoUWxRWjJybFdKT1lXNUtRQ1ZSa2lTUlRZaFdSa0Zpc0FVV0tlUWlwRWlaNk5mb0VkRjZlTlBzUVFvQTZRZFFETWhCOEU=",
      "compressionType": "DEFLATE",
      "fileExtension": ".html",
      "parentId": "http://www.example.com/",
      "permissions": [
        {
          "allowAnonymous": false,
          "allowedPermissions": [
            // ...Allowed security identities...
          ],
          "deniedPermissions": [
            // ...Denied security identities...
          ]
        },
        // ...More permission sets...
      ]
    },
    // ...More items to add or update...
  ],
  "delete": [
    {
      "documentId": "http://www.example.com/todelete.html",
      "deleteChildren": true
    },
    // ...More items to delete...
  ]
}

Successful response - 200 OK

{}

Step 3: Push the file container into a Push source

Use the PUT /sources/{sourceId}/documents/batch HTTP request to push the Amazon S3 file container into a Push source.

Sequence diagram for PUT batch request
Sequence diagram highlighting the PUT /sources/{sourceId}/documents/batch request in the context of a batch update sequence and illustrating how the Coveo indexing pipeline handles the batch update.

==

Request definition

PUT https://api.cloud.coveo.com/push/v1/organizations/<MyOrganizationId>/sources/<MySourceId>/documents/batch?fileId=<MyFileId> HTTP/1.1

Content-Type: application/json
Authorization: Bearer <MyAccessToken>

Request body

{}

In the request path:

In the query string:

In the Authorization HTTP header:

A successful response (202 Accepted) has no content, but indicates that the operation was successfully forwarded to the service and that the batch of items is now enqueued to be processed by the Coveo indexing pipeline.

Note

This doesn’t imply that all items in the batch were successfully added, updated and/or deleted in the target Push source (see About the Push API processing delay).

Tip
Leading practice: Update the status of your Push source

If you set your Push source to an active status before, you should consider setting it back to the IDLE status once this operation has successfully returned, assuming you have no more operations to perform as part of this content update (see Updating the status of a Push source).

Sample request

The following example shows how to push a file container into a Push source.

Request definition

PUT https://api.cloud.coveo.com/push/v1/organizations/mycoveocloudv2organizationg8tp8wu3/sources/mycoveocloudv2organization-rp5rxzbdz753uhndklv2ztkfgy/documents/batch?fileId=b5e8767e-8f0d-4a89-9095-1127915c89c7 HTTP/1.1

Content-Type: application/json
Authorization: Bearer **********-****-****-****-************

Request body

{}

Successful response - 202 Accepted

null