# Getting DocumentAlreadyExistException even if there is no document?

**URL:** <https://discuss.elastic.co/t/getting-documentalreadyexistexception-even-if-there-is-no-document/7464>\
**Category:** Elasticsearch\
**Created:** [April 25, 2012, 12:00pm UTC](https://discuss.elastic.co/t/getting-documentalreadyexistexception-even-if-there-is-no-document/7464 "2012-04-25T12:00:17Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![cheepu](https://avatars.discourse-cdn.com/v4/letter/c/e9a140/32.png) [@cheepu](https://discuss.elastic.co/u/cheepu)\
**Post date:** [April 25, 2012, 12:00pm UTC](https://discuss.elastic.co/t/getting-documentalreadyexistexception-even-if-there-is-no-document/7464/1 "2012-04-25T12:00:17Z")

</div>

Hi all,

```
            I am deleting an indextype and again creating indextype in 

```

the same index with same indextype name.  
When i create indextype with same name, i get the exception that  
"DocumentAlredyExist" As I know that this exception is raised when there  
exist an document with same id. But I have deleted my indextype then there  
is no question of the existance of any document. I also check indextype  
existance by checking metadata of index(before creating indextype); there  
also I get that no indextype exist. Now it is sucking me that why this  
exception is raised. Also I have observer that If i repeat the task of  
deletion and creation of indextype; sometime i get this exception and some  
time not.

I am checking existence of indextype as follows:

ClusterStateResponse response =  
client.admin().cluster().prepareState().execute().actionGet();  
ImmutableMap\<String, MappingMetaData\> mappings =  
response.state().getMetaData().index(indexName).getMappings();  
boolean hasIndexType = mappings.containsKey(indexType);

Following way is used to delete indextype:

DeleteMappingResponse actionGet =  
client.admin().indices().prepareDeleteMapping(indexName).setType(indexType).execute().actionGet();  
RefreshRequestBuilder prepareRefresh =  
client.admin().indices().prepareRefresh(indexName);  
RefreshResponse refreshActionGet =  
prepareRefresh.execute().actionGet();

Thanks  
Cheepu

---

<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:** [July 6, 2017, 3:31am UTC](https://discuss.elastic.co/t/getting-documentalreadyexistexception-even-if-there-is-no-document/7464/2 "2017-07-06T03:31:11Z")

</div>


