ArcGIS Pro 3.4 API Reference Guide
ArcGIS.Core.Data.DDL Namespace / AttributeIndexDescription Class
Members Example Version

AttributeIndexDescription Class
Represents a mechanism to create an attribute ArcGIS.Core.Data.Index.
Object Model
AttributeIndexDescription ClassTableDescription Class
Syntax
public sealed class AttributeIndexDescription : IndexDescription 
Example
Create Attribute Indexes on KG Schemas with SchemaBuilder
await QueuedTask.Run(() =>
{
  using (var kg = GetKnowledgeGraph())
  {
    if (kg == null)
      return;

    var entity_name = "PhoneCall";

    //indexes are managed on the GDB objects...
    var entity_table_def = kg.GetDefinition<TableDefinition>(entity_name);
    var entity_table_desc = new TableDescription(entity_table_def);


    var entity_table_flds = entity_table_def.GetFields();
    AttributeIndexDescription attr_index1 = null;
    AttributeIndexDescription attr_index2 = null;
    foreach (var fld in entity_table_flds)
    {
      //index the first string field
      if (fld.FieldType == FieldType.String && attr_index1 == null)
      {
        if (fld.Name == "ESRI__ID")//special case
          continue;
        //Index _must_ be ascending for KG
        attr_index1 = new AttributeIndexDescription(
          "Index1", entity_table_desc, new List<string> { fld.Name })
        {
          IsAscending = true
        };
      }
      //index the first numeric field (if there is one)
      if ((fld.FieldType == FieldType.BigInteger ||
           fld.FieldType == FieldType.Integer ||
           fld.FieldType == FieldType.Single ||
           fld.FieldType == FieldType.SmallInteger ||
           fld.FieldType == FieldType.Double) && attr_index2 == null)
      {
        attr_index2 = new AttributeIndexDescription(
          "Index2", entity_table_desc, new List<string> { fld.Name })
        {
          IsAscending = true,
          IsUnique = true //optional - unique if all values are to be unique in the index
        };
      }
      if (attr_index1 != null && attr_index2 != null) break;
    }

    if (attr_index1 == null && attr_index2 == null)
      return; //nothing to index

    //Run the schema builder
    try
    {
      SchemaBuilder sb = new(kg);
      if (attr_index1 != null)
        sb.Create(attr_index1);
      if (attr_index2 != null)
        sb.Create(attr_index2);
      if (!kg.ApplySchemaEdits(sb))
      {
        var err_msg = string.Join(",", sb.ErrorMessages.ToArray());
        System.Diagnostics.Debug.WriteLine($"Create index error: {err_msg}");
      }
    }
    catch (Exception ex)
    {
      System.Diagnostics.Debug.WriteLine(ex.ToString());
    }
  }
});
Delete Attribute Indexes on KG Schemas with SchemaBuilder
await QueuedTask.Run(() =>
{
  using (var kg = GetKnowledgeGraph())
  {
    if (kg == null)
      return;

    var entity_name = "PhoneCall";

    //indexes are managed on the GDB objects...
    var entity_table_def = kg.GetDefinition<TableDefinition>(entity_name);
    var entity_table_desc = new TableDescription(entity_table_def);

    var indexes = entity_table_def.GetIndexes();
    foreach (var idx in indexes)
    {
      System.Diagnostics.Debug.WriteLine($"Index {idx.GetName()}");
    }
    var idx1 = indexes.FirstOrDefault(
      idx => idx.GetName().ToLower() == "Index1".ToLower());
    var idx2 = indexes.FirstOrDefault(
      idx => idx.GetName().ToLower() == "Index2".ToLower());

    if (idx1 == null && idx2 == null)
      return;

    //Run the schema builder
    try
    {
      SchemaBuilder sb = new(kg);

      if (idx1 != null)
      {
        var idx_attr = new AttributeIndexDescription(idx1, entity_table_desc);
        sb.Delete(idx_attr);
      }
      if (idx2 != null)
      {
        var idx_attr = new AttributeIndexDescription(idx2, entity_table_desc);
        sb.Delete(idx_attr);
      }

      if (!kg.ApplySchemaEdits(sb))
      {
        var err_msg = string.Join(",", sb.ErrorMessages.ToArray());
        System.Diagnostics.Debug.WriteLine($"Delete index error: {err_msg}");
      }
    }
    catch (Exception ex)
    {
      System.Diagnostics.Debug.WriteLine(ex.ToString());
    }
  }
});
Inheritance Hierarchy

System.Object
   ArcGIS.Core.Data.DDL.Description
      ArcGIS.Core.Data.DDL.IndexDescription
         ArcGIS.Core.Data.DDL.AttributeIndexDescription

Requirements

Target Platforms: Windows 11, Windows 10

ArcGIS Pro version: 3.1 or higher.
See Also