ALIYUN::OTS::SearchIndex类型用于在数据表上创建一个多元索引。一个数据表可以创建多个多元索引。

语法

{
  "Type": "ALIYUN::OTS::SearchIndex",
  "Properties": {
    "IndexName": String,
    "InstanceName": String,
    "TableName": String,
    "FieldSchemas": List,
    "IndexSort": Map,
    "IndexSetting": Map
  }
}

属性

属性名称 类型 必须 允许更新 描述 约束
IndexName String 多元索引名称。
InstanceName String 数据表所属的实例名称。
TableName String 数据表名称。
FieldSchemas List 字段结构。
IndexSort Map 索引预排序设置。默认按照主键排序。 含有Nested类型的索引不支持IndexSort,没有预排序。

更多信息,请参见IndexSort属性

IndexSetting Map 索引设置。 更多信息,请参见IndexSetting属性

IndexSort语法

"IndexSort": {
  "Sorters": List
}

IndexSort属性

属性名称 类型 必须 允许更新 描述 约束
Sorters List 索引的预排序方式。 支持按照主键排序和字段值排序。

更多信息,请参见排序和翻页Sorters属性

Sorters语法

"Sorters": [
  {
    "FieldSort": Map,
    "PrimaryKeySort": Map,
    "ScoreSort": Map,
    "GeoDistanceSort": Map
  }
]

Sorters属性

属性名称 类型 必须 允许更新 描述 约束
FieldSort Map 按照字段值排序。 更多信息,请参见FieldSort属性
PrimaryKeySort Map 按照主键排序。 更多信息,请参见PrimaryKeySort属性
ScoreSort Map 按照查询结果的相关性(BM25算法)分数进行排序,适用于有相关性的场景,例如:全文检索等。 如果需要按照相关性打分进行排序,必须手动设置ScoreSort,否则会按照索引设置的IndexSort进行排序。

更多信息,请参见ScoreSort属性

GeoDistanceSort Map 根据地理点距离进行排序。 更多信息,请参见GeoDistanceSort属性

FieldSort语法

"FieldSort": {
  "SortMode": String,
  "SortOrder": String,
  "FieldName": String
}

FieldSort属性

属性名称 类型 必须 允许更新 描述 约束
SortMode String 当字段存在多个值时的排序方式。
SortOrder String 排序的顺序。 取值:
  • 升序(默认值):ASC。
  • 降序:DESC。
FieldName String 排序的字段名。

PrimaryKeySort语法

"PrimaryKeySort": {
  "SortOrder": String
}

PrimaryKeySort属性

属性名称 类型 必须 允许更新 描述 约束
SortOrder String 排序的顺序。 取值:
  • 升序(默认值):ASC。
  • 降序:DESC。

ScoreSort语法

"ScoreSort": {
  "SortOrder": String
}

ScoreSort属性

属性名称 类型 必须 允许更新 描述 约束
SortOrder String 排序顺序。 取值:
  • 升序(默认值):ASC。
  • 降序:DESC。

GeoDistanceSort语法

"GeoDistanceSort": {
  "Points": List,
  "SortMode": String,
  "SortOrder": String,
  "FieldName": String
}

GeoDistanceSort属性

属性名称 类型 必须 允许更新 描述 约束
Points List 组成多边形范围的坐标,通过多个坐标可以确定一个唯一的多边形。 格式为纬度,经度,纬度在前,经度在后,且纬度范围为[-90,+90],经度范围[-180,+180]。例如:35.8,-45.91
SortMode String 当字段存在多个值时的排序方式。
SortOrder String 排序顺序。 取值:
  • 升序(默认值):ASC。
  • 降序:DESC。
FieldName String 排序的字段名。

IndexSetting语法

"IndexSetting": {
  "RoutingFields": List
}

IndexSetting属性

属性名称 类型 必须 允许更新 描述 约束
RoutingFields List 自定义路由字段。 您可以选择部分主键列作为路由字段,在进行索引数据写入时,会根据路由字段的值计算索引数据的分布位置,路由字段的值相同的记录会被索引到相同的数据分区中。

返回值

Fn::GetAtt

IndexName:多元索引名称。

示例

JSON格式

{
  "ROSTemplateFormatVersion": "2015-09-01",
  "Parameters": {
    "IndexName": {
      "Type": "String",
      "Description": "The index name."
    },
    "InstanceName": {
      "Type": "String",
      "Description": "The name of the OTS instance in which table will locate.",
      "AllowedPattern": "[a-zA-Z][-a-zA-Z0-9]{1,14}[a-zA-Z0-9]"
    },
    "TableName": {
      "Type": "String",
      "Description": "The table name of the OTS instance.",
      "AllowedPattern": "[_a-zA-Z][_a-zA-Z0-9]{0,254}"
    },
    "FieldSchemas": {
      "Type": "Json",
      "Description": "list of field_schema."
    },
    "IndexSort": {
      "Type": "Json",
      "Description": "This parameter specifies how data is sorted. \nBy default, the data is sorted in the same way as the primary key of the table. \nIf the search index contains NESTED fields, data is not sorted by default."
    },
    "IndexSetting": {
      "Type": "Json",
      "Description": "Index settings"
    }
  },
  "Resources": {
    "SearchIndex": {
      "Type": "ALIYUN::OTS::SearchIndex",
      "Properties": {
        "IndexName": {
          "Ref": "IndexName"
        },
        "InstanceName": {
          "Ref": "InstanceName"
        },
        "TableName": {
          "Ref": "TableName"
        },
        "FieldSchemas": {
          "Ref": "FieldSchemas"
        },
        "IndexSort": {
          "Ref": "IndexSort"
        },
        "IndexSetting": {
          "Ref": "IndexSetting"
        }
      }
    }
  },
  "Outputs": {
    "IndexName": {
      "Description": "Index name.",
      "Value": {
        "Fn::GetAtt": [
          "SearchIndex",
          "IndexName"
        ]
      }
    }
  }
}

YAML格式

ROSTemplateFormatVersion: '2015-09-01'
Parameters:
  IndexName:
    Type: String
    Description: The index name.
  InstanceName:
    Type: String
    Description: The name of the OTS instance in which table will locate.
    AllowedPattern: '[a-zA-Z][-a-zA-Z0-9]{1,14}[a-zA-Z0-9]'
  TableName:
    Type: String
    Description: The table name of the OTS instance.
    AllowedPattern: '[_a-zA-Z][_a-zA-Z0-9]{0,254}'
  FieldSchemas:
    Type: Json
    Description: list of field_schema.
  IndexSort:
    Type: Json
    Description: >-
      This parameter specifies how data is sorted. 

      By default, the data is sorted in the same way as the primary key of the
      table. 

      If the search index contains NESTED fields, data is not sorted by default.
  IndexSetting:
    Type: Json
    Description: Index settings
Resources:
  SearchIndex:
    Type: 'ALIYUN::OTS::SearchIndex'
    Properties:
      IndexName:
        Ref: IndexName
      InstanceName:
        Ref: InstanceName
      TableName:
        Ref: TableName
      FieldSchemas:
        Ref: FieldSchemas
      IndexSort:
        Ref: IndexSort
      IndexSetting:
        Ref: IndexSetting
Outputs:
  IndexName:
    Description: Index name.
    Value:
      'Fn::GetAtt':
        - SearchIndex
        - IndexName