为数据表创建多元索引后,您可以查看多元索引列表、查看多元索引信息、使用多元索引查询数据以及删除多元索引。

创建多元索引

创建一个多元索引。

  • 命令格式
    create_search_index -n search_index_name

    配置项说明请参见下表。

    配置项 是否必填 示例值 说明
    -n,--name search_index 多元索引名称。
    -t,--table mytable 数据表名称。
  • 示例

    创建search_index多元索引。

    create_search_index -n search_index
    根据系统提示输入索引Schema,示例如下:
     {
    
        "IndexSetting": {
            "RoutingFields": null
        },
        "FieldSchemas": [
            {
                "FieldName": "gid",
                "FieldType": "LONG",
                "Index": true,
                "EnableSortAndAgg": true,
                "Store": true,
                "IsArray": false,
                "IsVirtualField": false
            },
            {
                "FieldName": "uid",
                "FieldType": "LONG",
                "Index": true,
                "EnableSortAndAgg": true,
                "Store": true,
                "IsArray": false,
                "IsVirtualField": false
            },
            {
                "FieldName": "col2",
                "FieldType": "LONG",
                "Index": true,
                "EnableSortAndAgg": true,
                "Store": true,
                "IsArray": false,
                "IsVirtualField": false
            },
            {
                "FieldName": "col3",
                "FieldType": "TEXT",
                "Index": true,
                "Analyzer": "single_word",
                "AnalyzerParameter": {
                    "CaseSensitive": true,
                    "DelimitWord": null
                },
                "EnableSortAndAgg": false,
                "Store": true,
                "IsArray": false,
                "IsVirtualField": false
            },
            {
                "FieldName": "col1",
                "FieldType": "KEYWORD",
                "Index": true,
                "EnableSortAndAgg": true,
                "Store": true,
                "IsArray": false,
                "IsVirtualField": false
            },
            {
                "FieldName": "col3V",
                "FieldType": "LONG",
                "Index": true,
                "EnableSortAndAgg": true,
                "Store": true,
                "IsArray": false,
                "IsVirtualField": true,
                "SourceFieldNames": [
                    "col3"
                ]
            }
        ]
    }

查看多元索引列表

查看当前数据表下多元索引的列表。

  • 命令格式
    list_search_index
    配置项说明请参见下表。
    配置项 是否必填 示例值 说明
    -a,--all 不涉及 显示所有表的多元索引列表。
    -d,--detail 不涉及 显示多元索引的详细信息。
  • 示例

    查看当前表下的多元索引列表。

    list_search_index
    返回结果如下:
    +-----------+--------------+
    | TableName | IndexName    |
    +-----------+--------------+
    | mytable   | search_index |
    +-----------+--------------+

查看多元索引信息

查看多元索引的信息。

  • 命令格式
    describe_search_index -n search_index_name
  • 示例

    查看search_index多元索引的信息。

    describe_search_index -n search_index

使用多元索引查询数据

使用多元索引查询满足指定条件的数据以及对数据进行统计聚合操作。

  • 命令格式
    search -n search_index_name --return_all_indexed
  • 示例

    使用search_index多元索引查询表中数据,并返回所有建立索引的列。

    search -n search_index --return_all_indexed
    根据系统提示输入查询条件,示例如下:
    {
        "Offset": -1,
        "Limit": 10,
        "Collapse": null,
        "Sort": null,
        "GetTotalCount": true,
        "Token": null,
        "Query": {
            "Name": "TermQuery",
            "Query": {
                "FieldName": "uid",
                "Term": 10001
            }
        },
        "Aggregations": [{
            "Name": "avg",
            "Aggregation": {
                "AggName": "agg1",
                "Field": "pid"
            }
        }]
    }

删除多元索引

删除不需要的多元索引。

  • 命令格式
    drop_search_index -n search_index_name
  • 示例

    删除search_index多元索引。

    drop_search_index -n search_index