# Documents not deleted when recreating same index

**URL:** <https://discuss.elastic.co/t/documents-not-deleted-when-recreating-same-index/76743>\
**Category:** Elasticsearch\
**Created:** [February 28, 2017, 9:01am UTC](https://discuss.elastic.co/t/documents-not-deleted-when-recreating-same-index/76743 "2017-02-28T09:01:57Z")\
**Posts on this page:** 8\
**Page:** 1

<div class="post-metadata">

**Author:** ![vinodMS](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vinodms/32/13476_2.png) [@vinodMS](https://discuss.elastic.co/u/vinodMS)\
**Post date:** [February 28, 2017, 9:01am UTC](https://discuss.elastic.co/t/documents-not-deleted-when-recreating-same-index/76743/1 "2017-02-28T09:01:57Z")

</div>

Hello there,

I have a simple python script to create indices. This script checks if the index already exists, if so it first deletes the index and then recreates it. The problem I face is that, once I recreate this particular index, the document count does not go to 0.

I run the stat api on the index, as soon as I recreate it and this is what I get.

```
{
   "_shards": {
      "total": 10,
      "successful": 5,
      "failed": 0
   },
   "_all": {
      "primaries": {
         "docs": {
            "count": 22,
            "deleted": 168
         },
         "store": {
            "size_in_bytes": 54195,
            "throttle_time_in_millis": 0
         },
         "indexing": {
            "index_total": 1140,
            "index_time_in_millis": 107,
            "index_current": 0,
            "index_failed": 0,
            "delete_total": 0,
            "delete_time_in_millis": 0,
            "delete_current": 0,
            "noop_update_total": 0,
            "is_throttled": false,
            "throttle_time_in_millis": 0
         },
         "get": {

```

Does anyone an idea what's going on here?

---

<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:** [February 28, 2017, 9:08am UTC](https://discuss.elastic.co/t/documents-not-deleted-when-recreating-same-index/76743/2 "2017-02-28T09:08:04Z")

</div>

How do you know it deletes and creates it, and there's not something else creating it?

---

<div class="post-metadata">

**Author:** ![vinodMS](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vinodms/32/13476_2.png) [@vinodMS](https://discuss.elastic.co/u/vinodMS)\
**Post date:** [February 28, 2017, 9:18am UTC](https://discuss.elastic.co/t/documents-not-deleted-when-recreating-same-index/76743/3 "2017-02-28T09:18:34Z")

</div>

My script returns the responses.

```
vinod@web4 ~/es> ./init.py
Enter tda_languagepair id: 1
Index already exists
deleting en-us_zh-hk index...
 response: {u'acknowledged': True}
creating en-us_zh-hk index...
 response: {u'acknowledged': True, u'shards_acknowledged': True}
```

---

<div class="post-metadata">

**Author:** ![vinodMS](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vinodms/32/13476_2.png) [@vinodMS](https://discuss.elastic.co/u/vinodMS)\
**Post date:** [March 3, 2017, 12:49pm UTC](https://discuss.elastic.co/t/documents-not-deleted-when-recreating-same-index/76743/4 "2017-03-03T12:49:25Z")

</div>

Do you have any updates on this for me? I have added my mapping template below, incase you'd like to take a look.

```
{
	"template": "logstash-*",
	"settings" : {
		"number_of_shards" : 5,
	    "number_of_replicas" : 1,
	    "index.refresh_interval": "60s",
	    "index" : {}
	},
	"mappings": {
		"segment": {
	    	"_parent": {
	        	"type": "tm"
	        },
	        "_routing": {
	          "required": "true"
	        },
	        "properties": {
	        	"@timestamp": {
	        		"type": "date",
	            	"format": "strict_date_optional_time||epoch_millis"
	          	},
		        "@version": {
		        	"type": "string"
		        },
		        "id": {
		        	"type": "long"
		        },
		        "lastmodified": {
		        	"type": "date",
		            "format": "strict_date_optional_time||epoch_millis"
		        },
		        "source": {
		        	"type": "string",
		            "store": "true"
		        },
		       	"sourcewordcount": {
		        	"type": "long"
		        },
		        "target": {
		        	"type": "string",
		            "store": "true"
		        },
		        "targetwordcount": {
		            "type": "long"
		        },
		        "upload_id": {
		            "type": "long",
		            "store": "false"
		        },
		        "sourceDigest": {
		            "type": "string"
		        },
		        "targetDigest": {
		            "type": "string"
		        }
			}
		},
		"tm": {
	    	"properties": {
	        	"@timestamp": {
	            	"type": "date",
	            	"format": "strict_date_optional_time||epoch_millis"
	          	},
	          	"@version": {
	            	"type": "string"
	          	},
	          	"contenttype": {
	            	"type": "string"
	          	},
	          	"dataowner": {
	            	"type": "string"
	          	},
	          	"dataSource": {
	            	"type": "string"
	          	},
	          	"id": {
	            	"type": "long"
	          	},
	          	"industry": {
	            	"type": "string"
	          	},
	          	"sourcelanguage": {
	            	"type": "string"
	          	},
	          	"tags": {
	            	"type": "string"
	          	},
	          	"targettanguage": {
	            	"type": "string"
	          	}
	        }
		}
	}
}
```

---

<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:** [March 4, 2017, 9:00pm UTC](https://discuss.elastic.co/t/documents-not-deleted-when-recreating-same-index/76743/5 "2017-03-04T21:00:31Z")

</div>

And what's that python doing, can you post it?

---

<div class="post-metadata">

**Author:** ![vinodMS](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/vinodms/32/13476_2.png) [@vinodMS](https://discuss.elastic.co/u/vinodMS)\
**Post date:** [March 6, 2017, 1:34pm UTC](https://discuss.elastic.co/t/documents-not-deleted-when-recreating-same-index/76743/6 "2017-03-06T13:34:36Z")

</div>

Sure, here you go,

```
def delete_index(es, indexName):
    #delete if already exists
    if es.indices.exists(indexName):
        print("deleting %s index..." % indexName)
        res = es.indices.delete(index = indexName)
        print(" response: %s" % res)

def create_index(es, indexName):
    #create request body
    f = open("http_log_logstash.json", "r")
    request_body = f.read()

    print("creating %s index..." % indexName)
    res = es.indices.create(index = indexName, body = request_body, ignore = 400)
    print(" response: %s " % res)
```

---

<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:** [March 8, 2017, 7:39pm UTC](https://discuss.elastic.co/t/documents-not-deleted-when-recreating-same-index/76743/7 "2017-03-08T19:39:16Z")

</div>

And what's in `http_log_logstash.json`.

---

<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:** [April 5, 2017, 7:39pm UTC](https://discuss.elastic.co/t/documents-not-deleted-when-recreating-same-index/76743/8 "2017-04-05T19:39:20Z")

</div>

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