Before you perform operations on a document, you must create an index for the document. This topic describes how to use Alibaba Cloud Elasticsearch to create an index.

Background information

The sample code provided in this topic is only suitable for Elasticsearch V6.7. For more information about the code for other versions, see Index API.

Procedure

  1. Log on to the Kibana console of your Elasticsearch cluster.
    For more information, see Log on to the Kibana console.
  2. In the left-side navigation pane, click Dev Tools.
  3. On the Console tab, run the following command to create an index named product_info.
    PUT /product_info
    {
      "settings": {
        "number_of_shards": 5,
        "number_of_replicas": 1
      },
      "mappings": {
        "products": {
          "properties": {
            "productName": {"type": "text","analyzer": "ik_smart"},
            "annual_rate":{"type":"keyword"},
            "describe": {"type": "text","analyzer": "ik_smart"}
          }
        }
      }
    }
    Notice In open-source Elasticsearch 7.0.0 and later, mapping types are removed. However, these mapping types are still supported in earlier versions. For more information, see Removal of mapping types. If mapping types are used in Elasticsearch 7.0.0 and later, the system displays "type": "mapper_parsing_exception".

    The preceding example creates an index named product_info. The index is of the products type and contains the productName, annual_rate, and describe fields.

    If the index is created, the following result is returned:
    {
      "acknowledged" : true,
      "shards_acknowledged" : true,
      "index" : "product_info"
    }