lib/aerospike/client.rb
def create_index(namespace, set_name, index_name, bin_name, index_type, collection_type = nil, options = nil)
      if options.nil? && collection_type.is_a?(Hash)
        options, collection_type = collection_type, nil
      end
      policy = create_policy(options, Policy, default_info_policy)

      str_cmd = "sindex-create:ns=#{namespace}"
      str_cmd << ";set=#{set_name}" unless set_name.to_s.strip.empty?
      str_cmd << ";indexname=#{index_name};numbins=1"
      str_cmd << ";indextype=#{collection_type.to_s.upcase}" if collection_type
      str_cmd << ";indexdata=#{bin_name},#{index_type.to_s.upcase}"
      str_cmd << ";priority=normal"

      # Send index command to one node. That node will distribute the command to other nodes.
      response = send_info_command(policy, str_cmd).upcase
      if response == 'OK'
        # Return task that could optionally be polled for completion.
        return IndexTask.new(@cluster, namespace, index_name)
      end

      if response.start_with?('FAIL:200')
        # Index has already been created.  Do not need to poll for completion.
        return IndexTask.new(@cluster, namespace, index_name, true)
      end

      raise Aerospike::Exceptions::Aerospike.new(Aerospike::ResultCode::INDEX_GENERIC, "Create index failed: #{response}")
    end
def create_index(namespace, set_name, index_name, bin_name, index_type, collection_type = nil, options = nil)
      if options.nil? && collection_type.is_a?(Hash)
        options, collection_type = collection_type, nil
      end
      policy = create_policy(options, Policy, default_info_policy)

      str_cmd = "sindex-create:ns=#{namespace}"
      str_cmd << ";set=#{set_name}" unless set_name.to_s.strip.empty?
      str_cmd << ";indexname=#{index_name};numbins=1"
      str_cmd << ";indextype=#{collection_type.to_s.upcase}" if collection_type
      str_cmd << ";indexdata=#{bin_name},#{index_type.to_s.upcase}"
      str_cmd << ";priority=normal"

      # Send index command to one node. That node will distribute the command to other nodes.
      response = send_info_command(policy, str_cmd).upcase
      if response == 'OK'
        # Return task that could optionally be polled for completion.
        return IndexTask.new(@cluster, namespace, index_name)
      end

      if response.start_with?('FAIL:200')
        # Index has already been created.  Do not need to poll for completion.
        return IndexTask.new(@cluster, namespace, index_name, true)
      end

      raise Aerospike::Exceptions::Aerospike.new(Aerospike::ResultCode::INDEX_GENERIC, "Create index failed: #{response}")
    end
Create secondary index.
  This asynchronous server call will return before command is complete.
  The user can optionally wait for command completion by using the returned
  IndexTask instance.

  This method is only supported by Aerospike 3 servers.
  index_type should be :string, :numeric or :geo2dsphere (requires server version 3.7 or later)
  collection_type should be :list, :mapkeys or :mapvalues