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
Thanks
// EDIT: found the (stupid) mistake:
I passed array($data) instead of just $data, which wasnt apparent because of the unfortunate error message.