Create an index

Updated at:

Run a CLI command to create an index for a specified LogStore. You must create an index before you can use the query or SQL analysis features.

Prerequisites

Before you run the CLI command, make sure that the following requirements are met:

  • SLS is activated. For more information, see Getting started with Simple Log Service.

  • The SLS CLI is installed and configured. For more information, see Install the CLI and Configure the CLI.

  • A project and a LogStore are created. For more information, see Create a project and Create a LogStore.

Note

When you create an index, you must configure at least one of the following: full-text index (line) or field index (keys).

An index takes effect within approximately one minute after creation. The index applies only to newly written data. To apply the index to historical data, you must manually rebuild the index.

Command syntax

aliyun sls create-index --project=<value> --logstore=<value> [--line=<value>] [--keys=<value>]

Parameters

The following table describes the required and command-specific parameters.

Parameter

Type

Required

Example

Description

--project

String

Yes

aliyun-test-project

The name of the project.

--logstore

String

Yes

aliyun-test-logstore

The name of the LogStore.

--line

String

No

See example

The full-text index configuration in JSON format. Supports keyword-based searches. Fields include: caseSensitive (whether the search is case-sensitive), chn (whether to include Chinese characters), and token (the list of delimiters).

--keys

String

No

See example

The field index configuration in JSON format. Supports field-based filtering and SQL analysis. Each field includes the following properties: type (the field type: text, long, double, or json), doc_value (whether to enable the analysis feature; we recommend setting this to true), alias (the field alias), caseSensitive (whether the search is case-sensitive), chn (whether to include Chinese characters), and token (the list of delimiters).