aerospike-community / spring-data-aerospike-starters

spring-data-aerospike-starters
https://github.com/aerospike-community/spring-data-aerospike
15 stars 7 forks source link

[Request] Add example with Map data type with Value index #136

Closed s8sg closed 1 year ago

s8sg commented 2 years ago

It will be great to have some example for querying the MapValue index type in Spring

I have similar problem where I have index I have a customer defined as

public class Customer {
  @Id private int id;

  @Indexed(
      name = "idxPartnerToken",
      type = IndexType.STRING,
      collectionType = IndexCollectionType.DEFAULT)
  private String partnerToken;

  @Field("externalRefs")
  @Indexed(type = STRING, collectionType = IndexCollectionType.MAPVALUES)
  Map<ExternalReferenceType, String> externalRefs;

  List<Segment> segments;

  private OffsetDateTime createdTime;
  private String createdBy;

  private OffsetDateTime updatedTime;
  private String updatedBy;
}

I'm trying to get the data using

Mono<Customer> findCustomerByPartnerToken(String partnerToken);
Mono<Customer> findCustomerByExternalRefs(
      String externalReferenceId, CriteriaDefinition.AerospikeMapCriteria criteria);

I'm calling it

customerReactiveAerospikeRepository.findCustomerByExternalRefs(
            externalReferenceId, CriteriaDefinition.AerospikeMapCriteria.VALUE);

But this fails to match the data where below works

customerReactiveAerospikeRepository.findCustomerByPartnerToken(token);

I tested with AQL

 SELECT * FROM test.customer IN MAPVALUES WHERE externalRefs = "56789"

and it works.

Data:

+-----------+-----------------------------------+-----------------------------------------------+-----------------------+
| PK        | externalRefs                      | @_class                                       | partnerToken          |
+-----------+-----------------------------------+-----------------------------------------------+-----------------------+
| "4049415" | MAP('{"GOJEK_CUSTOMER":"56789"}') | "com.test.customerservice.document.Customer" | "P-6924584.212981942" |
+-----------+-----------------------------------+-----------------------------------------------+-----------------------+

Can you suggest what I'm doing wrong

agrgr commented 1 year ago

Hi @s8sg,

Thanks for opening the issue. This is Starters repository, an auto-configuration project. The more suitable place for questions like the current one is sping-data-aerospike repository.

You can query map for values using the following approach:

Repository entry:

Mono<Customer> findByExternalRefsContaining(
            String externalReferenceId, CriteriaDefinition.AerospikeMapCriteria criteria);

Calling it:

customerReactiveAerospikeRepository.findByExternalRefsContaining(
            externalReferenceId, CriteriaDefinition.AerospikeMapCriteria.VALUE);

P.S. Today we released a new version of Spring Data Aerospike 3.5.0 (can take up to 24 hours to sync in Maven Central, so likely to be found there starting Oct 27th, and a new version of spring-data-aerospike-starters is planned to be released on Oct 28th).