# Deleting and immediately recreating a document type leads to error

**URL:** <https://community.swiftype.com/t/deleting-and-immediately-recreating-a-document-type-leads-to-error/631>\
**Category:** API\
**Created:** [March 23, 2018, 9:01am UTC](https://community.swiftype.com/t/deleting-and-immediately-recreating-a-document-type-leads-to-error/631 "2018-03-23T09:01:13Z")\
**Posts on this page:** 2\
**Page:** 1

<div class="post-metadata">

**Author:** ![stefan](https://sea1.discourse-cdn.com/flex019/user_avatar/community.swiftype.com/stefan/32/139_2.png) [@stefan](https://community.swiftype.com/u/stefan)\
**Post date:** [March 23, 2018, 9:01am UTC](https://community.swiftype.com/t/deleting-and-immediately-recreating-a-document-type-leads-to-error/631/1 "2018-03-23T09:01:14Z")

</div>

Hey.  
To clear all indexed items we first delete a document type and recreate it immediately. Unfortunately we get an error on creating the document type:  
`{ "error": "Invalid record. \nmessage:\n Validation of DocumentType failed.\nsummary:\n The following errors were found: Name is already taken\nresolution:\n Try persisting the document with valid data or remove the validations." }`

If we wait some time (i.e. using `sleep(3)`) everything works fine.

Q: Is there a better solution than using `sleep()`? The post request is made synchronous.

---

<div class="post-metadata">

**Author:** ![mike](https://sea1.discourse-cdn.com/flex019/user_avatar/community.swiftype.com/mike/32/37_2.png) [@mike](https://community.swiftype.com/u/mike)\
**Post date:** [March 27, 2018, 10:27pm UTC](https://community.swiftype.com/t/deleting-and-immediately-recreating-a-document-type-leads-to-error/631/2 "2018-03-27T22:27:08Z")

</div>

Hey Stefan,

Thanks for reporting this! I’ve passed it along to our engineering team and we’re currently evaluating solutions.
