Manage batches of items in a Push source
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.
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.
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
|
Request body
|
Replace:
-
<MyUploadUri>
with the value of theuploadUri
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 therequiredHeaders
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
).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 thecompressedBinaryDataFileId
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.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.Leading practice: Specify a fileExtensionAlthough 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 totrue
if you want to recursively delete all items whosedocumentId
is nested under thedocumentId
to delete, or set it tofalse
otherwise.NoteThe
deleteChildren
property is set tofalse
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
|
Request body
|
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.
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
|
Request body
|
In the request path:
-
Replace
<MyOrganizationId>
with the actual ID of the target Coveo organization (see Retrieve the organization ID). -
Replace
<MySourceId>
with the actual ID of the target Push source (see Create a Push source).
In the query string:
-
Replace
<MyFileId>
with thefiledId
you got from Step 1: Create a file container.
In the Authorization
HTTP header:
-
Replace
<MyAccessToken>
with an access token that grants the Sources - Edit privilege on the target source (see Create an API key, Get the privileges of an access token, and Get your Coveo access token).
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). |
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 |
Sample request
The following example shows how to push a file container into a Push source.
Request definition
|
Request body
|
Successful response - 202 Accepted
|