You can call this operation to create one or more Searchindex structures in an existing primary table. You can specify the index name and index structure when creating the Searchindex structure.

Parameters

  • TableName: the name of the table where you want to create a Searchindex structure.

  • IndexName: the name of the Searchindex structure.

  • IndexSchema: includes the IndexSetting and FieldSchemas parameters. You can use IndexSetting to set indexes, and use FieldSchemas to set all attributes of an index.

    • IndexSetting

      RoutingFields: you use this advanced optional feature to customize a routing. You can specify some primary key columns as routing fields. Table Store distributes data that is written to an index to different partitions according to the specified routing fields. The data with the same routing field value is distributed to the same partition.

    • FieldSchemas
      Parameter Required Description
      FieldName Yes
      • String type.
      • The name of a field that you want to index.
      • The attribute can be a primary key column or an attribute column.
      FieldType Yes Enumeration type. FieldType supports the following types:
      • LONG (long integer)
      • DOUBLE (floating-point number)
      • BOOLEAN (Boolean type)
      • KEYWORD (string type)
      • TEXT (tokenized string type)
      • GEO_POINT (geographical location type)
      • NESTED (nested type)
      Index No You can specify this parameter to enable indexing the target attribute.
      IndexOptions No The optional index setting.
      Analyzer No The optional tokenizer setting.
      EnableSortAndAgg No
      • The optional Boolean value.
      • You can specify this parameter to enable sorting and statistics.
      Store No
      • The optional Boolean value.
      • You can specify this parameter to store the value of the target field to the Searchindex structure.
      • If you set the parameter to true, you can read data directly from the index without searching the primary table. This optimizes query performance.
      Array No
      • The optional Boolean value.
      • You can specify this parameter to indicate whether the column is an array.
      • A value of true indicates that the column is an array. Data written to the column must be a JSON array, such as ["a","b","c"]. A NESTED column is an array, and does not require the Array attribute.
    • IndexSort: the optional parameter to indicate the presorting method for indexed data. You can sort data by primary keys or columns. You sort data by primary keys by default.

Examples

Example 1

You can create a Searchindex structure that consists of the Col_Keyword and Col_Long columns. Then, set the data type of these columns to KEYWORD and LONG, respectively.


private static void createSearchIndex(SyncClient client) {
    CreateSearchIndexRequest request = new CreateSearchIndexRequest();
    request.setTableName(TABLE_NAME); // Set the name of the table.
    request.setIndexName(INDEX_NAME); // Set the name of the index.
    IndexSchema indexSchema = new IndexSchema();
    indexSchema.setFieldSchemas(Arrays.asList(
            new FieldSchema("Col_Keyword", FieldType.KEYWORD) // Set the field name and field type.
                    .setIndex(true) // Set the parameter to true to enable indexing.
                    .setEnableSortAndAgg(true), // Set the parameter to true to enable sorting and statistics.
            new FieldSchema("Col_Long", FieldType.LONG)
                    .setIndex(true)
                    .setEnableSortAndAgg(true)));
    request.setIndexSchema(indexSchema);
    client.createSearchIndex(request); // Use client to create a Searchindex structure.
}
Example 2

Specify the IndexSort parameter.

private static void createSearchIndexWithIndexSort(SyncClient client) {
    CreateSearchIndexRequest request = new CreateSearchIndexRequest();
    request.setTableName(TABLE_NAME);
    request.setIndexName(INDEX_NAME);
    IndexSchema indexSchema = new IndexSchema();
    indexSchema.setFieldSchemas(Arrays.asList(
            new FieldSchema("Col_Keyword", FieldType.KEYWORD).setIndex(true).setEnableSortAndAgg(true),
            new FieldSchema("Col_Long", FieldType.LONG).setIndex(true).setEnableSortAndAgg(true),
            new FieldSchema("Col_Text", FieldType.TEXT).setIndex(true),
            new FieldSchema("Timestamp", FieldType.LONG).setIndex(true).setEnableSortAndAgg(true)));
    // Presort data by the Timestamp column. You must index the Timestamp column and enable the EnableSortAndAgg feature.
    indexSchema.setIndexSort(new Sort(
            Arrays. <Sort.Sorter>asList(new FieldSort("Timestamp", SortOrder.ASC))));
    request.setIndexSchema(indexSchema);
    client.createSearchIndex(request);
}