Creating an index
The first operation to do before starting indexing data in ElasticSearch is to create an index: the main container of our data.
An index is similar to the concept of a database in SQL.
Getting ready
You need a working ElasticSearch cluster.
How to do it...
The HTTP method to create an index is PUT (but POST also works), the REST URL is the index name, which is written as follows:
http://<server>/<index_name>
For creating an index, we need to perform the following steps:
From command line, we can execute a
PUT
call as follows:curl -XPUT http://127.0.0.1:9200/myindex -d '{ "settings" : { "index" : { "number_of_shards" : 2, "number_of_replicas" : 1 } } }'
The result returned by ElasticSearch, if everything is all right, should be as follows:
{"ok":true,"acknowledged":true}
If the index already exists, a 400 error is returned:
{"error":"IndexAlreadyExistsException[[myindex] Already exists]","status":400}
How it works...
There...