# \[PHP\] Bulk-indexing works, add/update single document fails with remote\_transport\_exception

**URL:** <https://discuss.elastic.co/t/php-bulk-indexing-works-add-update-single-document-fails-with-remote-transport-exception/163096>\
**Category:** Elasticsearch\
**Created:** [January 6, 2019, 8:32pm UTC](https://discuss.elastic.co/t/php-bulk-indexing-works-add-update-single-document-fails-with-remote-transport-exception/163096 "2019-01-06T20:32:04Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![radonthetyrant](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/radonthetyrant/32/39518_2.png) [@radonthetyrant](https://discuss.elastic.co/u/radonthetyrant)\
**Post date:** [January 6, 2019, 8:32pm UTC](https://discuss.elastic.co/t/php-bulk-indexing-works-add-update-single-document-fails-with-remote-transport-exception/163096/1 "2019-01-06T20:32:04Z")

</div>

Hello,

I am on ES Version 6.5.4

I use this code to batch-index all documents (start fresh)

```
$params = ['body' => []];
    for ($i = 0, $n = count($user_data); $i < $n; $i++) {
        $user = $user_data[$i];
        $params['body'][] = [
            'index' => [
                '_index' => self::USER_IDX,
                '_type' => self::USER_IDX,
                '_id' => (int)$user['id'],
            ],
        ];

        $params['body'][] = $user;

        if ($i % 1000 == 0) {
            $responses = self::$client->bulk($params);
            $hasError = $hasError || $responses['errors'];
            if ($hasError) {
                return false;
            }
            $params = ['body' => []];
        }
    }

    if (!empty($params['body'])) {
        $responses = self::$client->bulk($params);
    }

```

This works.

Now imagine that I use one $user\_data array and rename it $data and the index and type still matches accordingly. Without looking at which fields changed, I want to "overwrite" whatever document under this index is in ES and replace all values with the new ones.  
When I try to add or update, for both operations I recieve an error, that follows the code snippets.

```
    public function addDocument($index, $id, $data)
{
    $response = self::$client->index(['index' => $index, 'type' => $index, 'id' => $id,
        'body' => [
            $data
        ]
    ]);

    return !$response['errors'];
}

public function updateDocument($index, $id, $data)
{
    $response = self::$client->update(['index' => $index, 'type' => $index, 'id' => $id,
        'body' => [
            'doc' => [
                $data
            ]
        ]
    ]);

    return !$response['errors'];
}

```

The Error from the caught exception for update, the error message is identical with add:

```
{"status":"fail","message":"Failed to update document: {\"error\":{\"root_cause\":[{\"type\":\"remote_transport_exception\",\"reason\":\"[yzS2_cW][127.0.0.1:9300][indices:data\/write\/update[s]]\"}],\"type\":\"not_x_content_exception\",\"reason\":\"Compressor detection can only be called on some xcontent bytes or compressed xcontent bytes\"},\"status\":500}"}

```

What am I doing wrong? I followed the documentation here: [https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/\_updating\_documents.html#\_partial\_document\_update](https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/_updating_documents.html#_partial_document_update)

Thanks

// EDIT: found the (stupid) mistake:

I passed array($data) instead of just $data, which wasnt apparent because of the unfortunate error message.

---

<div class="post-metadata">

**Author:** ![system](https://us1.discourse-cdn.com/elastic/original/3X/1/a/1ac57faf039f6b580b3f104ef42a2a89e41014de.png) [@system](https://discuss.elastic.co/u/system)\
**Post date:** [February 3, 2019, 8:32pm UTC](https://discuss.elastic.co/t/php-bulk-indexing-works-add-update-single-document-fails-with-remote-transport-exception/163096/2 "2019-02-03T20:32:08Z")

</div>

This topic was automatically closed 28 days after the last reply. New replies are no longer allowed.
