# delete\_by\_query

The function`delete_by_query(collection_name, body)` deletes all documents that match the query conditions&#x20;

**Input-**

* <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 documents to delete

**Example-**

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

```python
hyperspace_client.delete_by_query(collection_name, 
                            body = {"query": {
                                        "bool": {
                                            "must": {
                                                    "term": {
                                                        "department": "IT"
                                                    },
                                                }
                                        }
                                    })

```

{% endcode %}
{% endtab %}

{% tab title="Java" %}

```javascript
String queryJson =
                  "{" +
                  "  \"query\": {" +
                  "    \"bool\": {" +
                  "      \"must\": [" +
                  "        {" +
                  "          \"term\":{" +
                  "            \"department\":\"IT\"" +
                  "           }" +
                  "        }" +
                  "      ]" +
                  "    }" +
                  "  }" +
                  "}";
                  
JsonObject query = JsonParser.parseString(queryJson).getAsJsonObject();
DeleteByQueryRequest queryRequest = new DeleteByQueryRequest();
queryRequest.setQuery(query);
DeleteByQueryResponse response = client.deleteByQuery(collectionName, queryRequest);
System.out.println(response.getTook());
System.out.println(response.getDeleted());
```

{% endtab %}

{% tab title="JavaScript" %}

```javascript
await hyperspaceClient.deleteByQuery({
        index: collectionName,
        body: {
            query: {
                bool: {
                    must: {
                            term: {
                                department: "IT"
                            },
                        }
                }
            }
        }
    })
```

{% endtab %}
{% endtabs %}
