After a search index is created for a data table, you can list the names of search indexes, query information about the search index, query data by using the search index, and delete the search index.

Create a search index

You can create a search index.

  • Command syntax
    create_search_index -n search_index_name

    The following table describes the parameters you can configure to create a search index.

    Parameter Required Example Description
    -n, --name Yes search_index The name of the search index.
    -t, --table No mytable The name of the data table.
  • Examples

    The following sample code shows how to create a search index named search_index:

    create_search_index -n search_index
    The following sample code shows how to enter the index schema as prompted by the system:
     {
    
        "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 indexes

You can list search indexes that are created for the current data table.

  • Command syntax
    list_search_index
    The following table describes the parameters that you can configure to list search indexes that are created for the current data table.
    Parameter Required Example Description
    -a, --all No N/A Specifies that the search indexes of all data tables are displayed.
    -d, --detail No N/A Specifies that the details about the search indexes are displayed.
  • Examples

    The following sample code shows how to list the search indexes of the current data table:

    list_search_index
    The following result is returned:
    +-----------+--------------+
    | TableName | IndexName    |
    +-----------+--------------+
    | mytable   | search_index |
    +-----------+--------------+

Query information about a search index

You can query information about a search index.

  • Command syntax
    describe_search_index -n search_index_name
  • Example

    The following sample code shows how to query information about the search index named search_index:

    describe_search_index -n search_index

Query data by using a search index

You can query data that meets specified conditions by using a search index and then perform aggregation operations on the returned results.

  • Command syntax
    search -n search_index_name --return_all_indexed
  • Examples

    The following sample code shows how to query data by using the search index named search_index and return all columns for which indexing is enabled:

    search -n search_index --return_all_indexed
    The following sample code shows how to enter the query conditions as prompted by the system:
    {
        "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"
            }
        }]
    }

Delete a search index

You can delete a search index that you no longer need.

  • Command syntax
    drop_search_index -n search_index_name
  • Example

    The following sample code shows how to delete the search index named search_index:

    drop_search_index -n search_index