# 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 %}


---

# Agent Instructions: Querying This Documentation

If you need additional information that is not directly available in this page, you can query the documentation dynamically by asking a question.

Perform an HTTP GET request on the current page URL with the `ask` query parameter:

```
GET https://docs.hyper-space.io/hyperspace-docs/api-documentation/hyperspace-client/delete_by_query.md?ask=<question>
```

The question should be specific, self-contained, and written in natural language.
The response will contain a direct answer to the question and relevant excerpts and sources from the documentation.

Use this mechanism when the answer is not explicitly present in the current page, you need clarification or additional context, or you want to retrieve related documentation sections.
