Skip to content
This repository has been archived by the owner on Sep 21, 2021. It is now read-only.

Latest commit

 

History

History
80 lines (59 loc) · 2.7 KB

05_Create_Delete.asciidoc

File metadata and controls

80 lines (59 loc) · 2.7 KB

Creating an Index

Until now, we have created a new index by simply indexing a document into it. The index is created with the default settings, and new fields are added to the type mapping by using dynamic mapping. Now we need more control over the process: we want to ensure that the index has been created with the appropriate number of primary shards, and that analyzers and mappings are set up before we index any data.

To do this, we have to create the index manually, passing in any settings or type mappings in the request body, as follows:

PUT /my_index
{
    "settings": { ... any settings ... },
    "mappings": {
        "type_one": { ... any mappings ... },
        "type_two": { ... any mappings ... },
        ...
    }
}

In fact, if you want to, you can prevent the automatic creation of indices by adding the following setting to the config/elasticsearch.yml file on each node:

action.auto_create_index: false
Note

Later, we discuss how you can use [index-templates] to preconfigure automatically created indices. This is particularly useful when indexing log data: you log into an index whose name includes the date and, as midnight rolls over, a new properly configured index automatically springs into existence.

Deleting an Index

To delete an index, use the following request:

DELETE /my_index

You can delete multiple indices with this:

DELETE /index_one,index_two
DELETE /index_*

You can even delete all indices with this:

DELETE /_all
DELETE /*
Note

For some, the ability to delete all your data with a single command is a very scary prospect. If you want to eliminate the possibility of an accidental mass-deletion, you can set the following to true in your elasticsearch.yml:

action.destructive_requires_name: true

This restricts deletions to specific names, instead of allowing the special _all or wildcard options. You can also update this setting dynamically through the Cluster State API