# \_update\_by\_query with PHP API

**URL:** <https://discuss.elastic.co/t/update-by-query-with-php-api/317500>\
**Category:** Elasticsearch\
**Tags:** painless\
**Created:** [October 26, 2022, 10:05am UTC](https://discuss.elastic.co/t/update-by-query-with-php-api/317500 "2022-10-26T10:05:24Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![abkrim](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abkrim/32/20217_2.png) [@abkrim](https://discuss.elastic.co/u/abkrim)\
**Post date:** [October 26, 2022, 10:05am UTC](https://discuss.elastic.co/t/update-by-query-with-php-api/317500/1 "2022-10-26T10:05:24Z")

</div>

I am looking for some examples or documentation to help me know if it is possible to do a **\_update\_by\_query** with the PHP API. I have seen examples in the JS section, but I can't find anything on the subject in PHP

## Using curl or kibana

```auto
        POST analyzers/_update_by_query
        {
            "script": {
            "source": "ctx._source.name = 'Cambiame'",
            "lang": "painless"
          },
          "query": {
            "term": {
                "modem_id": {
                    "value": 1
              }
            }
          }
        }

```

---

<div class="post-metadata">

**Author:** ![RabBit\_BR](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/rabbit_br/32/82261_2.png) [@RabBit\_BR](https://discuss.elastic.co/u/RabBit_BR)\
**Post date:** [October 26, 2022, 11:34am UTC](https://discuss.elastic.co/t/update-by-query-with-php-api/317500/2 "2022-10-26T11:34:34Z")

</div>

Hello @abkrim

This [post](https://stackoverflow.com/a/49491381/18778181) can help you.

---

<div class="post-metadata">

**Author:** ![abkrim](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/abkrim/32/20217_2.png) [@abkrim](https://discuss.elastic.co/u/abkrim)\
**Post date:** [October 26, 2022, 11:56am UTC](https://discuss.elastic.co/t/update-by-query-with-php-api/317500/3 "2022-10-26T11:56:17Z")

</div>

A lot of thanks.

10 minutes ago, I see the post and modify my code.

```auto
$params = [
            'index' => 'analyzers',
            'body' => [
                'query' => [
                    'term' => [
                        'modem_id' => $modem_id
                    ]
                ],
                'script' => [
                    'lang' => 'painless',
                    'source' => "ctx._source.$field_change = params.$field_change",
                    'params' => [
                        $field_change => $value_change_me
                    ]
                ]
            ]
        ];

```

Work fine...

---

<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:** [November 23, 2022, 11:56am UTC](https://discuss.elastic.co/t/update-by-query-with-php-api/317500/4 "2022-11-23T11:56:38Z")

</div>

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