How to bulk update using PHP

Hi all,

i have followed this article
https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/_indexing_documents.html
to bulk index documents.,

but now i want to update the 2 fields of 70% of documents., and i need to do it 3 times a day.,
so i am looking into bulk update.

so after reading this

i used 'update' => [] action instead of'index' => [] action

now my code is giving me

{"error":{"root_cause":[{"type":"action_request_validation_exception","reason":"Validation Failed: 1: script or doc is missing;"}],"type":"action_request_validation_exception","reason":"Validation Failed: 1: script or doc is missing;"},"status":400}

my code looks like this.

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

for($i = 0; $i < count($results); $i++) {
    $params['body'][] = [
        'update' => [
            '_index' => $elastcsearch_index,
            '_type' => $elastcsearch_type,
            '_id' => $results[$i]['content_id']
        ]
    ];

    $params['body'][] = [
        'uploaders' => intval($results[$i]['uploaders']) ,
        'downloaders' => intval($results[$i]['downloaders'])
    ];

    // Every 1000 documents stop and send the bulk request
    if ($i % 1000 == 0) {
        $responses = $elasticsearch->bulk($params);

        // erase the old bulk request
        $params = ['body' => []];
		
		//printr($responses) ;
        // unset the bulk response when you are done to save memory
        unset($responses);
    }
}

// Send the last batch if it exists
if (!empty($params['body'])) {
    $responses = $elasticsearch->bulk($params);
}

Thanks for your time.

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