public function updateDocument($id, $data, $indexName, $typeName = '')
    {
        $index = $this->getIndex($indexName);
        $client = $index->getClient();
        $type = $index->getType(
            empty($typeName) ? $this->typeName : $typeName
        );

        // data array needs to have the key 'doc'
        $rawData = array(
            'doc' => $this->decorator->normalizeValue($data)
        );

        $response = $client->updateDocument(
            $id,
            $rawData,
            $index->getName(),
            $type->getName()
        );

        if ($response->hasError()) {

            $error = $this->normalizeError($response->getError());

            throw new AdaptorException(
                $error->getMessage(),
                $error->getCode(),
                $error
            );
        }

        $type->getIndex()->refresh();

        return $type->getDocument($id);
    }