API for create type


(Barsk) #1

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


(Clinton Gormley) #2

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).

http://www.elasticsearch.org/guide/reference/api/admin-indices-put-mapping.html

or when you create the index:

http://www.elasticsearch.org/guide/reference/api/admin-indices-create-index.html

clint


(Barsk) #3

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).
http://www.elasticsearch.org/guide/reference/api/admin-indices-put-mapping.html

or when you create the index:

http://www.elasticsearch.org/guide/reference/api/admin-indices-create-index.html

clint


(system) #4