
ElasticSearch Cookbook
By :

During the startup of an application, it's often necessary to check if an index or type exists otherwise we need to create them.
You need a working ElasticSearch cluster and the mapping available in the index as described in the previous recipes.
The HTTP method to check existence is HEAD
. The URL format for checking an index is as follows:
http://<server>/<index_name>/
The URL format for checking a type is as follows:
http://<server>/<index_name>/<type>/
For checking if an index exists, we need to perform the following steps:
If we consider the index created in the Creating an index recipe, the call will be as follows:
curl –i -XHEAD 'http://localhost:9200/myindex/'
If the index exists an HTTP status code 200 is returned, if missing a 404 is returned. For checking if a type exists, we need to perform the following steps:
If we consider the mapping created in the Putting a mapping in an index recipe...
Change the font size
Change margin width
Change background colour