Document JSON format - Put

The put object is used to add new or changed documents to Vespa. Also see conditional puts.

{
    "put": "id:music:music::http://music.yahoo.com/bobdylan/BestOf",
    "fields": {
        "songs": "Knockin on Heaven's Door; Mr. Tambourine Man",
        "title": "Best of Bob Dylan",
        "url": "http://music.yahoo.com/bobdylan/BestOf"
    }
}
The value of the put field is the document id which uniquely identifies the document and at the same time specifies the document type (matching one in the deployed application). Values for the document fields may be set using elements as shown above in the fields object. In this example, songs and title are fields specified in the document type.

Array values

Arrays are represented by using JSON arrays:

{
    "put": "id:arraydoctype:arraydoctype::example1",
    "fields": {
        "intarrayfield": [
            123,
            456,
            789
        ],
        "stringarrayfield": [
            "item 1",
            "item 2",
            "item 3"
        ]
    }
}

Map values

Maps are represented as JSON dictionaries. The key has to be a string.

{
    "put": "id:mapdoctype:mapdoctype::example1",
    "fields": {
        "inttostringmap":
            {
                "123": "foo",
                "456": "bar",
                "789": "foobar"
            }
    }
}
Refer to the reference for indexing restrictions using maps and structs.

Struct values

Structs are more or less directly represented as JSON objects, declared by their field name.

{
    "put": "id:structdoctype:structdoctype::example1",
    "fields": {
        "mystruct": {
            "intfield": 123,
            "stringfield": "foo"
        }
    }
}
Refer to the reference for indexing restrictions using maps and structs.

Weighted set values

Weighted sets are represented as maps where the value is the weight. Note, even if the key is not a string as such, it will be represented as a string in the JSON format. Default weight is 1.

{
    "put": "id:weightedsetdoctype:weightedsetdoctype::example1",
    "fields": {
        "intweightedsetfield": {
            "123": 2,
            "456": 78
        },
        "stringweightedsetfield": {
            "item 1": 143,
            "item 2": 6
        }
    }
}

base64 encoded values

Feeding raw fields are done by feeding the input data as a base64-encoded string.

{
    "put": "id:rawdoctype:rawdoctype::example1",
    "fields": {
        "rawfield": "VW5rbm93biBhcnRpc3QgZnJvbSB0aGUgbW9vbg=="
    }
}

Tensor values

Feeding a tensor field is done by specifying the cells of the tensor as follows:

{
    "put": "id:tensordoctype:tensordoctype::example1",
    "fields": {
        "tensorfield": {
            "cells": [
                { "address": { "x": "a", "y": "b" }, "value": 2.0 },
                { "address": { "x": "c", "y": "d" }, "value": 3.0 }
            ]
        }
    }
}
In this case we have a tensor with two mapped dimensions x and y where the tensor type as specfied in the sd-file is tensor(x{},y{}).

In the next example we have a tensor with two indexed dimensions x and y representing a 2x2 matrix. The tensor type in this case is tensor(x[2],y[2]).

{
    "put": "id:tensordoctype:tensordoctype::example2",
    "fields": {
        "tensorfield": {
            "cells": [
                { "address": { "x": "0", "y": "0" }, "value": 2.0 },
                { "address": { "x": "0", "y": "1" }, "value": 3.0 },
                { "address": { "x": "1", "y": "0" }, "value": 5.0 },
                { "address": { "x": "1", "y": "1" }, "value": 7.0 }
            ]
        }
    }
}