Creating a new index

Before we start adding any documents to Elasticsearch, we need to create an index first. An index in Elasticsearch is basically a named space where you can ingest data. Elasticsearch supports multiple indexes, handling right out of the box. We will take advantage of it by creating our own index for our exercise.

How to do it…

Run the following command to start a new index by using the HTTP PUT method:

curl -XPUT 'http://localhost:9200/news/'

This command should return the following:

{"acknowledged":true}

If the index already exists (for example, run the above command twice), you will see the following error message:

{"error":"IndexAlreadyExistsException[[news] already exists]","status":400}

To confirm the index is created, we can ...

Get Lucene 4 Cookbook now with the O’Reilly learning platform.

O’Reilly members experience books, live events, courses curated by job role, and more from O’Reilly and nearly 200 top publishers.