Class IndexSchema

java.lang.Object
com.redis.vl.schema.IndexSchema

public final class IndexSchema extends Object
Represents the schema definition for a Redis search index.

This class is final to prevent finalizer attacks, as it throws exceptions in constructors for input validation (SEI CERT OBJ11-J).

  • Method Details

    • fromYaml

      public static IndexSchema fromYaml(String yaml)
      Create IndexSchema from YAML string
      Parameters:
      yaml - the YAML string representation of the schema
      Returns:
      an IndexSchema instance parsed from the YAML
    • fromYamlFile

      public static IndexSchema fromYamlFile(String filepath)
      Create IndexSchema from YAML file
      Parameters:
      filepath - the path to the YAML file containing the schema
      Returns:
      an IndexSchema instance parsed from the YAML file
    • fromJson

      public static IndexSchema fromJson(String json)
      Create IndexSchema from JSON string
      Parameters:
      json - the JSON string representation of the schema
      Returns:
      an IndexSchema instance parsed from the JSON
    • fromDict

      public static IndexSchema fromDict(Map<String,Object> data)
      Create IndexSchema from dictionary (Map)
      Parameters:
      data - the map containing schema data
      Returns:
      an IndexSchema instance created from the map
    • builder

      public static IndexSchema.Builder builder()
      Create a builder
      Returns:
      a new Builder instance
    • of

      public static IndexSchema.Builder of(String name)
      Create with fluent API
      Parameters:
      name - the name of the index
      Returns:
      a new Builder instance with the name set
    • getName

      public String getName()
      Get the index name
      Returns:
      the index name
    • getPrefix

      public String getPrefix()
      Get the prefix
      Returns:
      the key prefix for documents in this index
    • getStorageType

      public IndexSchema.StorageType getStorageType()
      Get the storage type
      Returns:
      the storage type (HASH or JSON)
    • getFields

      public List<BaseField> getFields()
      Get a copy of the fields list
      Returns:
      a copy of the list of fields in this schema
    • getField

      public BaseField getField(String name)
      Get a field by name
      Parameters:
      name - the name of the field to retrieve
      Returns:
      the field with the given name, or null if not found
    • hasField

      public boolean hasField(String name)
      Check if a field exists
      Parameters:
      name - the name of the field to check
      Returns:
      true if a field with the given name exists, false otherwise
    • getFieldsByType

      public <T extends BaseField> List<T> getFieldsByType(Class<T> fieldType)
      Get fields of a specific type
      Type Parameters:
      T - the type of field to retrieve
      Parameters:
      fieldType - the class of the field type
      Returns:
      a list of fields matching the specified type
    • removeField

      public void removeField(String name)
      Remove a field by name
      Parameters:
      name - the name of the field to remove
    • addField

      public void addField(BaseField field)
      Add a single field
      Parameters:
      field - the field to add
    • addFields

      public void addFields(List<Map<String,Object>> fieldsData)
      Add multiple fields from a list of maps
      Parameters:
      fieldsData - list of maps containing field configuration data
    • toYaml

      public String toYaml()
      Serialize to YAML
      Returns:
      YAML string representation of this schema
    • toJson

      public String toJson()
      Serialize to JSON
      Returns:
      JSON string representation of this schema
    • getIndex

      public IndexSchema.Index getIndex()
      Get the index configuration (defensive copy)
      Returns:
      a copy of the Index configuration
    • equals

      public boolean equals(Object o)
      Overrides:
      equals in class Object
    • hashCode

      public int hashCode()
      Overrides:
      hashCode in class Object