# Delete all data streams when delete index through data stream API

**URL:** <https://discuss.elastic.co/t/delete-all-data-streams-when-delete-index-through-data-stream-api/286804>\
**Category:** Elasticsearch\
**Tags:** datastreams\
**Created:** [October 15, 2021, 7:44am UTC](https://discuss.elastic.co/t/delete-all-data-streams-when-delete-index-through-data-stream-api/286804 "2021-10-15T07:44:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![d4nnyx](https://avatars.discourse-cdn.com/v4/letter/d/e99b99/32.png) [@d4nnyx](https://discuss.elastic.co/u/d4nnyx)\
**Post date:** [October 15, 2021, 7:44am UTC](https://discuss.elastic.co/t/delete-all-data-streams-when-delete-index-through-data-stream-api/286804/1 "2021-10-15T07:44:37Z")

</div>

I have index "test-index", and other data streams but "test index" data stream.  
When I try to delete this "test-index" index through data stream API (and "test-index" data stream does not exist), I get "acknowledge: true" and all data streams are deleted.

Because of this, we had to solve data loss of all our logs, can you please confirm it's the very unpleasant bug?

Thanks.

---

<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:** [October 15, 2021, 8:10am UTC](https://discuss.elastic.co/t/delete-all-data-streams-when-delete-index-through-data-stream-api/286804/2 "2021-10-15T08:10:47Z")

</div>

Could you paste here the exact commands you ran?

Ideally a full reproduction script would help to understand what is happening.

---

<div class="post-metadata">

**Author:** ![d4nnyx](https://avatars.discourse-cdn.com/v4/letter/d/e99b99/32.png) [@d4nnyx](https://discuss.elastic.co/u/d4nnyx)\
**Post date:** [October 15, 2021, 6:28pm UTC](https://discuss.elastic.co/t/delete-all-data-streams-when-delete-index-through-data-stream-api/286804/3 "2021-10-15T18:28:40Z")

</div>

This creates some data streams and "test-index" index

```auto
for i in `seq 11 20`; do
# Creates a component template for mappings
curl --insecure -X PUT "https://user:pass@localhost:9200/_component_template/my-mappings-${i}?pretty" -H 'Content-Type: application/json' -d"
{
  \"template\": {
    \"mappings\": {
      \"properties\": {
        \"@timestamp\": {
          \"type\": \"date\",
          \"format\": \"date_optional_time||epoch_millis\"
        },
        \"message\": {
          \"type\": \"wildcard\"
        }
      }
    }
  },
  \"_meta\": {
    \"description\": \"Mappings for @timestamp and message fields\",
    \"my-custom-meta-field\": \"More arbitrary metadata\"
  }
}
"
# Creates a component template for index settings
curl --insecure -X PUT "https://user:pass@localhost:9200/_component_template/my-settings-${i}?pretty" -H 'Content-Type: application/json' -d"
{
  \"template\": {
    \"settings\": {
      \"index.lifecycle.name\": \"my-lifecycle-policy-${i}\"
    }
  },
  \"_meta\": {
    \"description\": \"Settings for ILM\",
    \"my-custom-meta-field\": \"More arbitrary metadata\"
  }
}
"
curl --insecure -X PUT "https://user:pass@localhost:9200/_index_template/my-index-template-${i}?pretty" -H 'Content-Type: application/json' -d"
{
  \"index_patterns\": [\"my-data-stream-${i}*\"],
  \"data_stream\": { },
  \"composed_of\": [\"my-mappings-${i}\", \"my-settings-${i}\"],
  \"priority\": 500${i},
  \"_meta\": {
    \"description\": \"Template for my time series data\",
    \"my-custom-meta-field\": \"More arbitrary metadata\"
  }
}
"
curl --insecure -X PUT "https://user:pass@localhost:9200/_data_stream/my-data-stream-${i}?pretty"
done

curl --insecure -X PUT "https://user:pass@localhost:9200/test-index

```

After that I will delete test index with data stream API

```auto
curl --insecure -X PUT "https://user:pass@localhost:9200/_data_stream/test-index

```

And all the data streams are gone.

---

<div class="post-metadata">

**Author:** ![warkolm](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/warkolm/32/39224_2.png) [@warkolm](https://discuss.elastic.co/u/warkolm)\
**Post date:** [October 18, 2021, 12:44am UTC](https://discuss.elastic.co/t/delete-all-data-streams-when-delete-index-through-data-stream-api/286804/4 "2021-10-18T00:44:09Z")

</div>

From [Delete data stream API | Elasticsearch Guide [7.15] | Elastic](https://www.elastic.co/guide/en/elasticsearch/reference/7.15/indices-delete-data-stream.html) (I've added the emphasis);

> Deletes one or more [data streams](https://www.elastic.co/guide/en/elasticsearch/reference/7.15/data-streams.html) **and their backing indices**

---

<div class="post-metadata">

**Author:** ![d4nnyx](https://avatars.discourse-cdn.com/v4/letter/d/e99b99/32.png) [@d4nnyx](https://discuss.elastic.co/u/d4nnyx)\
**Post date:** [October 18, 2021, 5:06am UTC](https://discuss.elastic.co/t/delete-all-data-streams-when-delete-index-through-data-stream-api/286804/5 "2021-10-18T05:06:06Z")

</div>

Not sure what you are trying to say.

The problem is deleting all other data streams in a cluster, not backing indices.

---

<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 15, 2021, 5:06am UTC](https://discuss.elastic.co/t/delete-all-data-streams-when-delete-index-through-data-stream-api/286804/6 "2021-11-15T05:06:08Z")

</div>

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