# How to bulk update using PHP

**URL:** <https://discuss.elastic.co/t/how-to-bulk-update-using-php/140344>\
**Category:** Elasticsearch\
**Created:** [July 17, 2018, 2:29pm UTC](https://discuss.elastic.co/t/how-to-bulk-update-using-php/140344 "2018-07-17T14:29:31Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![Shrimp-Fried-Rice](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/shrimp-fried-rice/32/33360_2.png) [@Shrimp-Fried-Rice](https://discuss.elastic.co/u/Shrimp-Fried-Rice)\
**Post date:** [July 17, 2018, 2:29pm UTC](https://discuss.elastic.co/t/how-to-bulk-update-using-php/140344/1 "2018-07-17T14:29:31Z")

</div>

Hi all,

i have followed this article  
[https://www.elastic.co/guide/en/elasticsearch/client/php-api/current/\_indexing\_documents.html](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

> <https://github.com/elastic/elasticsearch-php/issues/452>

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.

---

<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:** [August 14, 2018, 2:29pm UTC](https://discuss.elastic.co/t/how-to-bulk-update-using-php/140344/2 "2018-08-14T14:29:36Z")

</div>

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