graphdb/src/main/java/com/tinkerpop/blueprints/impls/orient/OrientBaseGraph.java
@SuppressWarnings({ "rawtypes" })
  @Override
  public <T extends Element> void createKeyIndex(final String key, final Class<T> elementClass,
      final Parameter... indexParameters) {
    makeActive();

    if (elementClass == null)
      throw ExceptionFactory.classForElementCannotBeNull();

    executeOutsideTx(new OCallable<OClass, OrientBaseGraph>() {
      @Override
      public OClass call(final OrientBaseGraph g) {

        String indexType = OClass.INDEX_TYPE.NOTUNIQUE.name();
        OType keyType = OType.STRING;
        String className = null;
        String collate = null;
        ODocument metadata = null;

        final String ancestorClassName = getClassName(elementClass);

        // READ PARAMETERS
        for (Parameter<?, ?> p : indexParameters) {
          if (p.getKey().equals("type"))
            indexType = p.getValue().toString().toUpperCase(Locale.ENGLISH);
          else if (p.getKey().equals("keytype"))
            keyType = OType.valueOf(p.getValue().toString().toUpperCase(Locale.ENGLISH));
          else if (p.getKey().equals("class"))
            className = p.getValue().toString();
          else if (p.getKey().equals("collate"))
            collate = p.getValue().toString();
          else if (p.getKey().toString().startsWith("metadata.")) {
            if (metadata == null)
              metadata = new ODocument();
            metadata.field(p.getKey().toString().substring("metadata.".length()), p.getValue());
          }
        }

        if (className == null)
          className = ancestorClassName;

        final ODatabaseDocument db = getRawGraph();
        final OSchema schema = db.getMetadata().getSchema();

        final OClass cls = schema.getOrCreateClass(className, schema.getClass(ancestorClassName));
        final OProperty property = cls.getProperty(key);
        if (property != null)
          keyType = property.getType();

        OPropertyIndexDefinition indexDefinition = new OPropertyIndexDefinition(className, key, keyType);
        if (collate != null)
          indexDefinition.setCollate(collate);
        db.getMetadata().getIndexManager()
            .createIndex(className + "." + key, indexType, indexDefinition, cls.getPolymorphicClusterIds(), null, metadata);
        return null;

      }
    }, "create key index on '", elementClass.getSimpleName(), ".", key, "'");
  }
@SuppressWarnings({ "rawtypes" })
  @Override
  public <T extends Element> void createKeyIndex(final String key, final Class<T> elementClass,
      final Parameter... indexParameters) {
    makeActive();

    if (elementClass == null)
      throw ExceptionFactory.classForElementCannotBeNull();

    executeOutsideTx(new OCallable<OClass, OrientBaseGraph>() {
      @Override
      public OClass call(final OrientBaseGraph g) {

        String indexType = OClass.INDEX_TYPE.NOTUNIQUE.name();
        OType keyType = OType.STRING;
        String className = null;
        String collate = null;
        ODocument metadata = null;

        final String ancestorClassName = getClassName(elementClass);

        // READ PARAMETERS
        for (Parameter<?, ?> p : indexParameters) {
          if (p.getKey().equals("type"))
            indexType = p.getValue().toString().toUpperCase(Locale.ENGLISH);
          else if (p.getKey().equals("keytype"))
            keyType = OType.valueOf(p.getValue().toString().toUpperCase(Locale.ENGLISH));
          else if (p.getKey().equals("class"))
            className = p.getValue().toString();
          else if (p.getKey().equals("collate"))
            collate = p.getValue().toString();
          else if (p.getKey().toString().startsWith("metadata.")) {
            if (metadata == null)
              metadata = new ODocument();
            metadata.field(p.getKey().toString().substring("metadata.".length()), p.getValue());
          }
        }

        if (className == null)
          className = ancestorClassName;

        final ODatabaseDocument db = getRawGraph();
        final OSchema schema = db.getMetadata().getSchema();

        final OClass cls = schema.getOrCreateClass(className, schema.getClass(ancestorClassName));
        final OProperty property = cls.getProperty(key);
        if (property != null)
          keyType = property.getType();

        OPropertyIndexDefinition indexDefinition = new OPropertyIndexDefinition(className, key, keyType);
        if (collate != null)
          indexDefinition.setCollate(collate);
        db.getMetadata().getIndexManager()
            .createIndex(className + "." + key, indexType, indexDefinition, cls.getPolymorphicClusterIds(), null, metadata);
        return null;

      }
    }, "create key index on '", elementClass.getSimpleName(), ".", key, "'");
  }
Creates an automatic indexing structure for indexing provided key for element class.

@param key             the key to create the index for
@param elementClass    the element class that the index is for
@param indexParameters a collection of parameters for the underlying index implementation: <ul> <li>"type" is the index type
between the supported types (UNIQUE, NOTUNIQUE, FULLTEXT). The default type is NOT_UNIQUE <li>"class" is
the class to index when it's a custom type derived by Vertex (V) or Edge (E) <li>"keytype" to use a key
type different by OType.STRING,</li></li> </ul>
@param <T>             the element class specification