# API for create type

**URL:** <https://discuss.elastic.co/t/api-for-create-type/4277>\
**Category:** Elasticsearch\
**Created:** [April 22, 2011, 3:46pm UTC](https://discuss.elastic.co/t/api-for-create-type/4277 "2011-04-22T15:46:09Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![Barsk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/barsk/32/13734_2.png) [@Barsk](https://discuss.elastic.co/u/Barsk)\
**Post date:** [April 22, 2011, 3:46pm UTC](https://discuss.elastic.co/t/api-for-create-type/4277/1 "2011-04-22T15:46:09Z")

</div>

Hi,  
maybe there is another way around this but my problem started with a  
search query that had an index and type already created.The query always  
returned a SearchResult. So I built my logic around that, i.e using the  
SearchResult object in my JSP page.

But when I restarted fresh I had no index and type created (only a  
mapping file) and as such I got some IndexMissing excpetions instead. I  
then created the index. But I still got exception due to the type that  
was missing.

There seems not to be a way to create a type. The only way to have the  
type created is to insert a dummy document and remove it. That way I  
finally got the SerachResult with 0 hits wich I expected in the first run...

Of course I could create some logic in the JSP page to handle null  
values for the SearchResult, but that would be much messier. I even  
tried to create an empty SearchResult, but there was no public  
constructor...

So, I would love if there was a way to create the type (which would put  
the index in a a state equal to that when the type exists, but has 0  
documents).

/Kristian

---

<div class="post-metadata">

**Author:** ![Clinton\_Gormley](https://avatars.discourse-cdn.com/v4/letter/c/50afbb/32.png) [@Clinton\_Gormley](https://discuss.elastic.co/u/Clinton_Gormley)\
**Post date:** [April 22, 2011, 3:50pm UTC](https://discuss.elastic.co/t/api-for-create-type/4277/2 "2011-04-22T15:50:05Z")

</div>

Hi Kristian

> So, I would love if there was a way to create the type (which would put  
> the index in a a state equal to that when the type exists, but has 0  
> documents).

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

or when you create the index:

> **[Elasticsearch Platform — Find real-time answers at scale](https://www.elastic.co)**
>
> Power insights and outcomes with the Elasticsearch Platform and AI. See into your data and find answers that matter with enterprise solutions designed to help you build, observe, and protect. Try Elasticsearch free today.

clint

---

<div class="post-metadata">

**Author:** ![Barsk](https://sea2.discourse-cdn.com/elastic/user_avatar/discuss.elastic.co/barsk/32/13734_2.png) [@Barsk](https://discuss.elastic.co/u/Barsk)\
**Post date:** [April 26, 2011, 3:47pm UTC](https://discuss.elastic.co/t/api-for-create-type/4277/3 "2011-04-26T15:47:30Z")

</div>

Yes, I am aware of the put-mapping API, but I do not put mappings  
explicitly from code. I have a mappings file that set things up. I could  
not find a way to put a mapping with reference to that file. If that  
exists all is well.

/Kristian

Clinton Gormley skrev 2011-04-22 17:50:

> Hi Kristian
> 
> > So, I would love if there was a way to create the type (which would put  
> > the index in a a state equal to that when the type exists, but has 0  
> > documents).  
> > [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/admin-indices-put-mapping.html)
> 
> or when you create the index:
> 
> [Elasticsearch Platform — Find real-time answers at scale | Elastic](http://www.elasticsearch.org/guide/reference/api/admin-indices-create-index.html)
> 
> clint

---

<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, 4:07am UTC](https://discuss.elastic.co/t/api-for-create-type/4277/4 "2017-07-06T04:07:39Z")

</div>


