Java Spring data aerospike“FindByatAttribute”操作神秘运行

Java Spring data aerospike“FindByatAttribute”操作神秘运行,java,nosql,spring-data,aerospike,aerospike-ce,Java,Nosql,Spring Data,Aerospike,Aerospike Ce,以下连结:- 我们有以下样本实体:- @Document(collection = "cust", expiration = 90, expirationUnit = TimeUnit.DAYS) public class Customer { @Id @Field(value = "PK") private String custId; @Field(value = "mobileNumber") p

以下连结:-

我们有以下样本实体:-

@Document(collection = "cust", expiration = 90, expirationUnit = TimeUnit.DAYS)
public class Customer {

   @Id
   @Field(value = "PK")
   private String custId;

   @Field(value = "mobileNumber")
   private String mobileNumber;

   @Field(value = "creationTime")
   private String creationTime;
 
@Field(value = "custType")
private String custType;
 
}
使用Spring存储库,我们使用以下方法:-

//工作 列出findByMobileNumber字符串mobileNumber

//失败,找不到201 ERR INNDEX。 列出FindBymobileEnumberAndCustType字符串mobileNumber、字符串customerType

事实/意见:-

一,。我们尚未在aerospike集合上创建任何明确的二级索引

二,。当我们使用AQL从test.cust(其中mobileNumber='981XXXXXXX'中查询同一记录)中选择*时,它失败,并给出一个未找到索引的错误

关注/问题:-

a。第一种方法是如何工作的?它的内部执行方式是什么?是否有任何在运行中的二级索引被创建,并在查询完成后立即被冲走

b。为什么第二个失败了

任何回复都将受到高度赞赏

为了使用**方法查找的spring数据,您应该为案例中的查询字段建立索引,为bin mobileNumber建立索引,否则,aerospike将需要对集合中的所有文档进行完全扫描,无论是否进行完全扫描,这取决于aerospike配置。索引不会自动创建。 所以,请以编程方式或手动方式创建索引。在以编程方式处理的情况下,可以使用以下方法:

public void createIndex(AerospikeRepository<?, ?> aerospikeRepository,
                        Class<?> entityClass,
                        String indexName,
                        String fieldName,
                        IndexType indexType) {
    var entityName = entityClass.getSimpleName();
    log.info("Creating Aerospike index [{}] for field [{}] of entity [{}]", indexName, fieldName, entityName);
    try {
        aerospikeRepository.createIndex(entityClass, indexName, fieldName, indexType);
        log.info("Aerospike index [{}] was successfully created for field [{}] of entity [{}]", indexName, fieldName, entityName);
    } catch (IndexAlreadyExistsException ex) {
        log.info("Aerospike index [{}] for field [{}] of entity [{}] already exists", indexName, fieldName, entityName);
    } catch (AerospikeException e) {
        if (e.getResultCode() == ResultCode.INDEX_ALREADY_EXISTS) {
            log.info("Aerospike index [{}] for field [{}] of entity [{}] already exists", indexName, fieldName, entityName);
            return;
        }
        throw e;
    }
}

不过,这样的索引只能通过单个字段mobileNumber获取记录,您需要按customerType过滤java代码中返回的结果,谢谢您回答这篇文章。帮助我回答这个问题:>>>>您应该为您的案例中的查询字段建立索引,为bin mobileNumber建立索引,否则,aerospike将需要对您集合中的所有文档进行完全扫描,无论是否进行完全扫描-取决于aerospike配置>>>允许或停止此操作的配置是什么??我们还没有做任何具体的这样的配置!
createIndex(customerRepository, Customer.class, "customer_mobileNumber_index", "mobileNumber", IndexType.STRING);