Detailed explanation of Elastic Search commands-index operation

For Elastic Search installation, please refer to " Elastic Search 8.6.2 Cluster Installation and Deployment " and for Kibana installation, please refer to "Elastic Search 8.6.2 Simple Operation". Relevant commands will be executed on the Console platform of the Kibana tool.

Elastic Search index operations mainly include: creating, deleting, closing and opening indexes, and index alias operations. Among them, the index alias operation is widely used in production environments and can be used in conjunction with closing or deleting the index. When using indexes in a production environment, special attention should be paid to data loss or abnormalities caused by improper operation.

1. Create an index

The first step in building a search engine using Elastic Search is to create an index. Create an index and initiate a request in PUT mode, command PUT /indexName

PUT /customer

{

  "settings":{

    "number_of_shards": 5, 

    "number_of_replicas": 2

  },

  "mappings":{

    "properties":{

      "name":{

        "type":"text"

      },

      "age":{

        "type": "integer"

      }

    }

  }

}

{

  "acknowledged": true,

  "shards_acknowledged": true,

  "index": "customer"

}

        

 

2. Delete index

Delete an index using DELETE /indexName

DELETE /customer

{

  "acknowledged": true

}

3. Close the index

Some indexes may not be used temporarily, but may be used in the future, and the index can be closed. When the index is closed, you can only use the Elastic Search API or monitoring tools to view the index information. At this time, the read and write operations on the index will report an error: index closing exception.

POST /customer/_close

{

  "acknowledged": true,

  "shards_acknowledged": true,

  "indices": {

    "customer": {

      "closed": true

    }

  }

}

4. Open the index

The index is closed. If you want to use it again, you can open the index again.

POST /customer/_open

{

  "acknowledged": true,

  "shards_acknowledged": true

Guess you like

Origin blog.csdn.net/Yu_Yangjun/article/details/129852592