# Delete multiple docs with matching multiple elements

**URL:** <https://discuss.elastic.co/t/delete-multiple-docs-with-matching-multiple-elements/166343>\
**Category:** Elasticsearch\
**Created:** [January 30, 2019, 11:41am UTC](https://discuss.elastic.co/t/delete-multiple-docs-with-matching-multiple-elements/166343 "2019-01-30T11:41:40Z")\
**Posts on this page:** 7\
**Page:** 1

<div class="post-metadata">

**Author:** ![kaushik.vankayala](https://avatars.discourse-cdn.com/v4/letter/k/aca169/32.png) [@kaushik.vankayala](https://discuss.elastic.co/u/kaushik.vankayala)\
**Post date:** [January 30, 2019, 11:41am UTC](https://discuss.elastic.co/t/delete-multiple-docs-with-matching-multiple-elements/166343/1 "2019-01-30T11:41:40Z")

</div>

Hi There,

I have the documents in my index in the following format;

```
{
  "_index": "mt_uat-app",
  "_type": "doc",
  "_id": "bR2vjmUBJkTWRy0yg7Y1",
  "_version": 1,
  "_score": 1,
  "_source": {
    "PartnerID": "wirecard",
    "Environment": "UAT",
    "loglevel": "INFO",
    "APITransactionId": "4d95e9b12cf0488084a22a8760c92c20",
    "audittype": "Audit-IN",
    "@timestamp": "2018-08-31T01:03:10.917Z",
    "PartnerUniqueID": "5d032ba3a5ff4c0aab7c5cb2cb6382c5",
    "CorrelationId": "baf56f70-ace7-11e8-b5ae-027cf458ba1c",
    "Request": "POST /api/experience/member/login",
    "ApplicationName": "experience-app",
  },
  "fields": {
    "@timestamp": [
      "2018-08-31T01:03:10.917Z"
    ]
  }
}

```

I intend to delete a set of docs that have matching APITransactionId. The list of APITransactionId is also a set.

I could delete the doc one at a time by delete\_by\_query API as follows;

```
POST mt_uat-app/_delete_by_query
{
  "query": { 
    "match": {
      "APITransactionId": "b0b808be30854a108c862451aa58e655"
    }
  }
}

```

But is there a way like if i have multiple APITransactionId and delete all docs that have that Id. I also tried to pass an array like below, but it doesnt work;

```
POST mt_uat-app/_delete_by_query
{
  "query": { 
    "match": {
      "APITransactionId": ["b0b808be30854a108c862451aa58e655", "4d7ac86f688e4163aa5264866ed72fca", "7931f54526274cc2b481c10ba7b6a3b2"]
    }
  }
}

```

Any solution and alternative approaches, please kindly suggest!

Regards

Kaushik

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 30, 2019, 11:55am UTC](https://discuss.elastic.co/t/delete-multiple-docs-with-matching-multiple-elements/166343/2 "2019-01-30T11:55:19Z")

</div>

You should use [https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-terms-query.html](https://www.elastic.co/guide/en/elasticsearch/reference/current/query-dsl-terms-query.html)

---

<div class="post-metadata">

**Author:** ![kaushik.vankayala](https://avatars.discourse-cdn.com/v4/letter/k/aca169/32.png) [@kaushik.vankayala](https://discuss.elastic.co/u/kaushik.vankayala)\
**Post date:** [January 30, 2019, 11:59am UTC](https://discuss.elastic.co/t/delete-multiple-docs-with-matching-multiple-elements/166343/3 "2019-01-30T11:59:41Z")

</div>

Worked like a charm. Thank you so much @dadoonet !

---

<div class="post-metadata">

**Author:** ![kaushik.vankayala](https://avatars.discourse-cdn.com/v4/letter/k/aca169/32.png) [@kaushik.vankayala](https://discuss.elastic.co/u/kaushik.vankayala)\
**Post date:** [January 30, 2019, 12:23pm UTC](https://discuss.elastic.co/t/delete-multiple-docs-with-matching-multiple-elements/166343/4 "2019-01-30T12:23:12Z")

</div>

@dadoonet Also, could you suggest how its possible to filter out the docs which have the count of APITransactionId exactly 1.

So in brief for every hit of an API, an Audit-IN and and an Audit-OUT will be generated which will have same APITransactionId. But if the api does not respond then we will **NOT** get an Audit-OUT.

I am looking for a DSL query probably with aggregation or an alternate approach to get all the docs which have the count of APITransactionId only 1, that way i get to filter out all docs which have only Audit-IN and NO Audit-OUT for a specific APITransactionId

_Any help appreciated!_

---

<div class="post-metadata">

**Author:** ![dadoonet](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/dadoonet/32/137187_2.png) [@dadoonet](https://discuss.elastic.co/u/dadoonet)\
**Post date:** [January 30, 2019, 12:37pm UTC](https://discuss.elastic.co/t/delete-multiple-docs-with-matching-multiple-elements/166343/5 "2019-01-30T12:37:09Z")

</div>

That's another question. You should open a new one.

---

<div class="post-metadata">

**Author:** ![kaushik.vankayala](https://avatars.discourse-cdn.com/v4/letter/k/aca169/32.png) [@kaushik.vankayala](https://discuss.elastic.co/u/kaushik.vankayala)\
**Post date:** [January 31, 2019, 4:07am UTC](https://discuss.elastic.co/t/delete-multiple-docs-with-matching-multiple-elements/166343/6 "2019-01-31T04:07:52Z")

</div>

Ohk will do, thank you! 🙂

I have posted it here (_[Get all docs with the occurrence of field values only once](https://discuss.elastic.co/t/get-all-docs-with-the-occurrence-of-field-values-only-once/166466?u=kaushik.vankayala)_) but could not get any responses till date. Could you kindly have a look if possible @dadoonet🙂 🤓

---

<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:** [February 28, 2019, 4:07am UTC](https://discuss.elastic.co/t/delete-multiple-docs-with-matching-multiple-elements/166343/7 "2019-02-28T04:07:53Z")

</div>

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