Esempio n. 1
0
        public static void CreateSearchIndex(OTSClient otsClient)
        {
            Console.WriteLine("\n Start Create searchindex...");

            CreateSearchIndexRequest request      = new CreateSearchIndexRequest(TableName, IndexName);
            List <FieldSchema>       FieldSchemas = new List <FieldSchema>()
            {
                new FieldSchema(Keyword_type_col, FieldType.KEYWORD)
                {
                    index = true, EnableSortAndAgg = true
                },
                new FieldSchema(Long_type_col, FieldType.LONG)
                {
                    index = true, EnableSortAndAgg = true
                },
                new FieldSchema(Text_type_col, FieldType.TEXT)
                {
                    index = true
                }
            };

            request.IndexSchame = new IndexSchema()
            {
                FieldSchemas = FieldSchemas
            };

            CreateSearchIndexResponse response = otsClient.CreateSearchIndex(request);

            Console.WriteLine("Searchindex is created: " + IndexName);
        }
        /// <summary>
        /// 创建一个多元索引,包含Keyword_type_col、Long_type_col、Text_type_col三个属性列,类型分别设置为不分词字符串(KEYWORD),整型(LONG),分词字符串(TEXT)
        /// </summary>
        /// <param name="otsClient"></param>
        public static void CreateSearchIndexWithIndexSort(OTSClient otsClient)
        {
            Console.WriteLine("\n Start Create searchindex with indexSort...");

            //指定表名和索引名
            CreateSearchIndexRequest request      = new CreateSearchIndexRequest(TableName, IndexName);
            List <FieldSchema>       FieldSchemas = new List <FieldSchema>()
            {
                new FieldSchema(Keyword_type_col, FieldType.KEYWORD) //设置字段名和字段类型
                {
                    index            = true,                         //开启索引
                    EnableSortAndAgg = true                          //开启排序和统计功能
                },
                new FieldSchema(Long_type_col, FieldType.LONG)
                {
                    index = true, EnableSortAndAgg = true
                },
                new FieldSchema(Text_type_col, FieldType.TEXT)
                {
                    index = true
                }
            };

            request.IndexSchame = new IndexSchema()
            {
                FieldSchemas = FieldSchemas,
                IndexSort    = new Sort(new List <ISorter>()
                {
                    new FieldSort(Long_type_col, SortOrder.ASC)
                })
            };

            CreateSearchIndexResponse response = otsClient.CreateSearchIndex(request);

            Console.WriteLine("Searchindex is created: " + IndexName);
        }