All Products
Search
Document Center

Simple Log Service:create_index

Last Updated:Oct 26, 2023

Creates indexes for a specified Logstore.

Request syntax

aliyunlog log create_index --project_name=<value> --logstore_name=<value> --index_detail=<value> [--access-id=<value>] [--access-key=<value>] [--sts-token=<value>] [--region-endpoint=<value>] [--client-name=<value>] [--jmes-filter=<value>] [--format-output=<value>] [--decode-output=<value>]

Request parameters

The following table describes the required and specific parameters of the create_index command.
ParameterTypeRequiredExampleDescription
--project_nameStringYesaliyun-test-projectThe name of the project.
--logstore_nameStringYeslogstroe-aThe name of the Logstore.
--index_detailJSON ObjectYesfile://./indexdetail.jsonThe path of the configuration file that is used to configure indexes. For more information, see Create indexes and GitHub.
For information about the global parameters of the Log Service command-line interface (CLI), see Global parameters.

Examples

  1. Create a file named indexdetail.json. The following example shows the content of the indexdetail.json file:
    {
      "keys": {
        "key1": {
          "caseSensitive": false,
          "token": [
            ",",
            " ",
            "'",
            "\"",
            ";",
            "=",
            "(",
            ")",
            "[",
            "]",
            "{",
            "}",
            "?",
            "@",
            "&",
            "<",
            ">",
            "/",
            ":",
            "\n",
            "\t"
          ],
          "type": "text",
          "doc_value": true
        },
        "key2": {
          "caseSensitive": false,
          "token": [
            ",",
            " ",
            "'",
            "\"",
            ";",
            "=",
            "(",
            ")",
            "[",
            "]",
            "{",
            "}",
            "?",
            "@",
            "&",
            "<",
            ">",
            "/",
            ":",
            "\n",
            "\t"
          ],
          "type": "text",
          "doc_value": true
        },
        "key3": {
          "caseSensitive": false,
          "token": [
            ",",
            " ",
            "'",
            "\"",
            ";",
            "=",
            "(",
            ")",
            "[",
            "]",
            "{",
            "}",
            "?",
            "@",
            "&",
            "<",
            ">",
            "/",
            ":",
            "\n",
            "\t"
          ],
          "type": "text",
          "doc_value": true
        },
        "key4": {
          "caseSensitive": false,
          "token": [
            ",",
            " ",
            "'",
            "\"",
            ";",
            "=",
            "(",
            ")",
            "[",
            "]",
            "{",
            "}",
            "?",
            "@",
            "&",
            "<",
            ">",
            "/",
            ":",
            "\n",
            "\t"
          ],
          "type": "text",
          "doc_value": true
        }
      },
      "storage": "pg",
      "ttl": 2,
      "index_mode": "v2",
      "line": {
        "caseSensitive": false,
        "token": [
          ",",
          " ",
          "'",
          "\"",
          ";",
          "=",
          "(",
          ")",
          "[",
          "]",
          "{",
          "}",
          "?",
          "@",
          "&",
          "<",
          ">",
          "/",
          ":",
          "\n",
          "\t"
        ]
      }
    }
  2. Use the default account to create indexes for a Logstore named logstore-a. Run the following command:
    aliyunlog log create_index --project_name="aliyun-test-project" --logstore_name="logstore-a" --index_detail="file://./indexdetail.json"
  3. Query index settings. Run the following command:
    aliyunlog log get_index_config --project_name="aliyun-test-project" --logstore_name="logstore-a" --format-output=json
    The following output is returned:
    {
      "index_mode": "v2",
      "keys": {
        "key1": {
          "caseSensitive": false,
          "doc_value": true,
          "token": [
            ",",
            " ",
            "'",
            "\"",
            ";",
            "=",
            "(",
            ")",
            "[",
            "]",
            "{",
            "}",
            "?",
            "@",
            "&",
            "<",
            ">",
            "/",
            ":",
            "\n",
            "\t"
          ],
          "type": "text"
        },
        "key2": {
          "caseSensitive": false,
          "doc_value": true,
          "token": [
            ",",
            " ",
            "'",
            "\"",
            ";",
            "=",
            "(",
            ")",
            "[",
            "]",
            "{",
            "}",
            "?",
            "@",
            "&",
            "<",
            ">",
            "/",
            ":",
            "\n",
            "\t"
          ],
          "type": "text"
        },
        "key3": {
          "caseSensitive": false,
          "doc_value": true,
          "token": [
            ",",
            " ",
            "'",
            "\"",
            ";",
            "=",
            "(",
            ")",
            "[",
            "]",
            "{",
            "}",
            "?",
            "@",
            "&",
            "<",
            ">",
            "/",
            ":",
            "\n",
            "\t"
          ],
          "type": "text"
        },
        "key4": {
          "caseSensitive": false,
          "doc_value": true,
          "token": [
            ",",
            " ",
            "'",
            "\"",
            ";",
            "=",
            "(",
            ")",
            "[",
            "]",
            "{",
            "}",
            "?",
            "@",
            "&",
            "<",
            ">",
            "/",
            ":",
            "\n",
            "\t"
          ],
          "type": "text"
        }
      },
      "lastModifyTime": 0,
      "line": {
        "caseSensitive": false,
        "chn": false,
        "token": [
          ",",
          " ",
          "'",
          "\"",
          ";",
          "=",
          "(",
          ")",
          "[",
          "]",
          "{",
          "}",
          "?",
          "@",
          "&",
          "<",
          ">",
          "/",
          ":",
          "\n",
          "\t"
        ]
      },
      "storage": "pg",
      "ttl": 30
    }

Error codes

If an error message is returned, fix the error based on the error codes of the related API operation. For more information, see Error codes of CreateIndex.

API reference

CreateIndex