Amazon CloudSearch
Developer Guide (API Version 2011-02-01)
« PreviousNext »
View the PDF for this guide.Go to the AWS Discussion Forum for this product.Go to the Kindle Store to download this guide in Kindle format.Did this page help you?  Yes | No |  Tell us about it...

documents/batch JSON API

JSON documents/batch Requests

The body of a documents/batch request uses SDF to specify the document operations you want to perform. An SDF JSON representation of a batch is a collection of objects that define individual add and delete operations. The type property identifies whether an object represents an add or delete operation. For example, the following JSON SDF batch adds one document and deletes one document:

[
{ "type": "add",
  "id":   "tt0484562",
  "version": 1,
  "lang": "en",
  "fields": {
    "title": "The Seeker: The Dark Is Rising",
    "director": "Cunningham, David L.",
    "genre": ["Adventure","Drama","Fantasy","Thriller"],
    "actor": ["McShane, Ian","Eccleston, Christopher","Conroy, Frances",
              "Crewson, Wendy","Ludwig, Alexander","Cosmo, James",
              "Warner, Amelia","Hickey, John Benjamin","Piddock, Jim",
              "Lockhart, Emma"]
  }
},
{ "type": "delete",
  "id":   "tt0484575",
  "version": 2
  }]

Note

When specifying SDF in JSON, the value for a field cannot be null.

An add or delete operation is only applied to an existing document if the version number specified in the operation is greater than the existing document's version number. If a batch contains multiple add or delete operations for the same document, the operation with the highest version number is applied. (If multiple operations in a batch specify the same document and version number, the document service arbitrarily picks which one to apply.)

The JSON schema representation of a batch is shown below:

{
    "type": "array",
    "minItems": 1,
    "items": {
        "type": "object",
        "properties": {
            "type": {
                "type": "string",
                "enum": ["add", "delete"],
                "required": true
            },
            "id": {
                "type": "string",
                "pattern": "[a-z0-9][a-z0-9_]{0,127}",
                "minLength": 1,
                "maxLength": 128,
                "required": true
            },
            "version": {
                "type": "number",
                "minimum": 1,
                "maximum": 4294967295
                "required": true
            },
            "lang": {
                "type": "string",
                "minLength": 2,
                "maxLength": 2
            },
            "fields": {
                "type": "object",
                "patternProperties": {
                    "[a-zA-Z0-9][a-zA-Z0-9_]{0,63}": {
                        "type": "string",
                    }
                }
            }
        }
    }
}

documents/batch Request Properties (JSON)

PropertyDescriptionRequired
typeThe operation type, add or delete. Yes
idAn alphanumeric string. Allowed characters are: a-z (lower-case letters), 0-9, and _ (underscore). Document IDs cannot begin with an underscore. The max length is 128 characters.Yes
versionAny non-negative number less than 2^32.Yes
langAn ISO-639-1 two-letter language code. English (en) is currently the only supported language.

Condition: Required for add operations.

Conditional
fieldsA collection of one or more field_name properties that define the fields the document contains.

Condition: Required for add operations. Must contain at least one field_name property.

Conditional
field_nameSpecifies a field within the document being added. Field names must begin with a letter and can contain the following characters: a-z (lower case), 0-9, and _ (underscore). Field names must be at least 3 and no more than 64 characters. The names "body", "docid", and "text_relevance" are reserved names and cannot be used as field names.

To specify multiple values for a field, you specify an array of values instead of a single value. For example:

"genre": ["Adventure","Drama","Fantasy","Thriller"]

Condition: At least one field must be specified in the fields object.

Conditional

documents/batch Response (JSON)

The response body lists the number of adds and deletes that were performed and any errors or warnings that were generated.

The JSON schema representation of a document service API response is shown below:

{
    "type": "object",
    "properties": {
        "status": {
            "type": "text",
            "enum": ["success", "error"],
            "required": true
        },
        "adds": {
            "type": "integer",
            "minimum": 0,
            "required": true
        },
        "deletes": {
            "type": "integer",
            "minimum": 0,
            "required": true
        },
        "errors": {
            "type": "array",
            "required": false,
            "items": {
                "type": "object",
                "properties": {
                    "message": {
                        "type": "string",
                        "required": true
                    }
                }
            }
        },
        "warnings": {
            "type": "array",
            "required": false,
            "items": {
                "type": "object",
                "properties": {
                    "message": {
                        "type": "string",
                        "required": true
                    }
                }
            }
        }
    }
}

documents/batch Response Properties (JSON)

PropertyDescription
statusThe result status, which is either success or error.
addsThe number of add document operations that were performed. Always zero when the status is error.
deletesThe number of delete document operations that were performed. Always zero when the status is error.
errorProvides information about a parsing or validation error. Specified only if the status is error.
warningProvides information about a warning generated during parsing or validation.