1. Sitecore CLI command reference

The CLI index command

The Sitecore indexing plugin includes an index command. This command automates indexing operations. To install the indexing plugin, run the following code:

bash
dotnet sitecore plugin add -n Sitecore.DevEx.Extensibility.Indexing

Usage

You can use the command as follows:

bash
dotnet sitecore index [subcommand] [options]

Subcommands

You can use the following subcommands:

  • list - provides the list of available indexes from the environment.
  • schema-populate - populates the managed schema.
  • rebuild - rebuilds all the indexes.
  • statistic - shows statistics of all the indexes.

All the subcommands require elevated permissions.

The list subcommand

The list subcommand provides the list of available indexes from the environment.

You can use the following options with the list subcommand:

OptionRequiredDescription
-n, --environment-name OptionalThe Sitecore environment to use. Default: default.
-c, --config OptionalPath to root sitecore.config directory (default: cwd).
-v, --verboseOptionalReport additional diagnostic and performance data.
-t, --traceOptionalReport additional diagnostic and performance data.
-?, -h, --helpOptionalHelp for the command.

For example:

bash
dotnet sitecore index list

The output of the command shows available indexes:

text
Indexes list:
sitecore_core_index
sitecore_master_index
sitecore_horizon_index

The schema-populate subcommand

The schema-populate subcommand populates the managed schema.

You can use the following options with the schema-populate subcommand:

OptionRequiredDescription
-i, --indexes OptionalPopulate the schema for specified indexes.
-n, --environment-name OptionalThe Sitecore environment to use. Default: default.
-c, --config OptionalPath to root sitecore.config directory (default: cwd).
-v, --verboseOptionalReport additional diagnostic and performance data.
-t, --traceOptionalReport additional diagnostic and performance data.
-?, -h, --helpOptionalHelp for the command.

You can use the command to populate specific indexes or all indexes.

For example, to populate a single index, you specify the name of the index using the -i option:

bash
dotnet sitecore index schema-populate -i sitecore_master_index

When the process finishes, it shows the result:

text
The search indexes have been populated.

Result:
sitecore_master_index [job ended]

Running the command without specifying any index populates all the indexes in the managed schema. For example:

bash
dotnet sitecore index schema-populate

When the process completes, it displays the populated indexes:

text
The search indexes have been populated.

Result:
sitecore_core_index   [job ended]
sitecore_master_index [job ended]

The rebuild subcommand

The rebuild subcommand rebuilds all the indexes.

You can use the following options with the rebuild subcommand:

OptionRequiredDescription
-i, --indexes OptionalRebuild the specified indexes.
-n, --environment-name OptionalThe Sitecore environment to use. Default: default.
-c, --config OptionalPath to root sitecore.config directory (default: cwd).
-v, --verboseOptionalReport additional diagnostic and performance data.
-t, --traceOptionalReport additional diagnostic and performance data.
-?, -h, --helpOptionalHelp for the command.

You can use the command to rebuild specific indexes or all indexes.

For example, to rebuild a single index, you specify the name of the index using the -i option:

bash
dotnet sitecore index rebuild -i sitecore_master_index

When the process finishes, it shows the result:

text
The search indexes have been rebuilt.

Result:
sitecore_master_index [job ended] [units processsed: 16620]

Running the command without specifying any index rebuilds all the indexes in the managed schema. For example:

bash
dotnet sitecore index rebuild

When the process finishes, it displays the rebuilt indexes and the number of processed units:

text
The search indexes have been rebuilt.

Result:
sitecore_core_index   [job ended] [units processsed: 13596]
sitecore_master_index [job ended] [units processsed: 16620]

The statistic subcommand

The statistic subcommand shows statistics of all the indexes.

You can use the following options with the statistic subcommand:

OptionRequiredDescription
-n, --environment-name OptionalThe Sitecore environment to use. Default: default.
-c, --configOptionalPath to root sitecore.config directory (default: cwd).
-t, --traceOptionalReport additional diagnostic and performance data.
-?, -h, --helpOptionalHelp for the command.

For example, running the command:

bash
dotnet sitecore index statistic

displays the following information about available indexes:

text
Index statistics:
 sitecore_core_index
  Rebuild Time: Never Run
  Last Updated: 08/13/2021 - 08:45 (UTC)
  Approximate Throughput: items per second
  Has Deletions: False
  Out of Date: False
  Document Count: 0
  Number of Fields: -1
  Number of Terms: -1
If you have suggestions for improving this article, let us know!