# update\_by\_query

The function `update_by_query(collection_name, body)` updatesl documents according to the query conditions&#x20;

**Input-**&#x20;

* <mark style="color:purple;">collection\_name</mark> – Specifies the Collection with the documents to delete
* <mark style="color:purple;">body</mark>– The query that specifies the conditions for documents to be updated

**Example-**

{% tabs %}
{% tab title="Python" %}
{% code lineNumbers="true" %}

```python
hyperspace_client.delete_by_query(collection_name, 
                            body = {"query": {
                                        "bool": {
                                            "must": {
                                                    "term": {
                                                        "name": "John"
                                                    },
                                                }
                                        },
                                    "script": "ctx._source.name = 'Bob'",
                                    })

```

{% endcode %}
{% endtab %}

{% tab title="Java" %}

```javascript
String queryJson =
                  "{" +
                  "  \"query\": {" +
                  "    \"bool\": {" +
                  "      \"must\": [" +
                  "        {" +
                  "          \"term\":{" +
                  "            \"name\":\"John\"" +
                  "           }" +
                  "        }" +
                  "      ]" +
                  "    }" +
                  "  }" +
                  "script: "ctx._source.name = \"Bob\"",
                  "}";
                  
JsonObject query = JsonParser.parseString(queryJson).getAsJsonObject();
DeleteByQueryRequest queryRequest = new DeleteByQueryRequest();
queryRequest.setQuery(query);
DeleteByQueryResponse response = client.uodateByQuery(collectionName, queryRequest);
System.out.println(response.getTook());
System.out.println(response.getDeleted());
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
await client.updateByQuery({
    index: collectionName,
    body: {
        query: {
            bool: {
                must: [
                    {
                        term: {
                            name: "John"
                        },
                    }
                ]
            }
        },
        script: "ctx._source.name = \"Bob\"",
    }
});
```

{% endtab %}
{% endtabs %}
