1

I am using Spring cloud to connect and read data from filestore (using Cloud Firestore in Native mode).

Pom.xml

<dependency>
        <groupId>org.springframework.cloud</groupId>
        <artifactId>spring-cloud-gcp-starter-data-datastore</artifactId>
</dependency>

Spring GCP version - <gcp.version>1.2.8.RELEASE</gcp.version>

Entity

import org.springframework.cloud.gcp.data.datastore.core.mapping.Entity;
import org.springframework.data.annotation.Id;

@Data
@AllArgsConstructor
@NoArgsConstructor
@Getter
@Setter
@Entity(name = "user_profile")
public class UserProfile {

    @Id
    private Long id;

    private String applicationId;

    private String firstName;

}

Repository

import org.springframework.cloud.gcp.data.datastore.repository.DatastoreRepository;

public interface UserProfileRepository extends DatastoreRepository<UserProfile, Long> {
    
    List<UserProfile> findByApplicationId(String applicationId);

}

Service


// Save
 public void register(UserRegistrationRequest dto) {
        
        UserProfile userProfile = new UserProfile();
        userProfile.setFirstName(dto.getFirstName());
    
        userProfile.setApplicationId(tkmIdGenerator.generate(UserType.Candidate));
            
        userProfileRepository.save(userProfile);
    }

// Get
 public void getUserDetails(String applicationId) {
        
        java.util.List<UserProfile> userProfiles = userProfileRepository.findByApplicationId(applicationId, Sort.by(Order.asc("applicationId")));
        System.out.println(userProfiles);
    }

The save works perfectly fine, but while trying to read it, getting below index not matching error. I am using single attribute to read the data. In this case firestore automatically creates the index. Bit confused why I am getting this error.

Error

com.google.datastore.v1.client.DatastoreException: no matching index found.
    at com.google.datastore.v1.client.RemoteRpc.makeException(RemoteRpc.java:136) ~[datastore-v1-proto-client-1.6.3.jar:na]
    at com.google.datastore.v1.client.RemoteRpc.makeException(RemoteRpc.java:185) ~[datastore-v1-proto-client-1.6.3.jar:na]
    at com.google.datastore.v1.client.RemoteRpc.call(RemoteRpc.java:96) ~[datastore-v1-proto-client-1.6.3.jar:na]
    at com.google.datastore.v1.client.Datastore.runQuery(Datastore.java:119) ~[datastore-v1-proto-client-1.6.3.jar:na]
    at com.google.cloud.datastore.spi.v1.HttpDatastoreRpc.runQuery(HttpDatastoreRpc.java:198) ~[google-cloud-datastore-1.105.3.jar:1.105.3]
    at com.google.cloud.datastore.DatastoreImpl$1.call(DatastoreImpl.java:194) ~[google-cloud-datastore-1.105.3.jar:1.105.3]
    at com.google.cloud.datastore.DatastoreImpl$1.call(DatastoreImpl.java:191) ~[google-cloud-datastore-1.105.3.jar:1.105.3]
    at com.google.api.gax.retrying.DirectRetryingExecutor.submit(DirectRetryingExecutor.java:105) ~[gax-1.60.1.jar:1.60.1]
  • you can add log statements to see what request contains? whether it contains a valid index or not? – vaibhavsahu Aug 21 '21 at 21:45
  • how to check from local environment (eclipse) if index is picked up or not ? – Sanjay Mohanty Aug 22 '21 at 13:39
  • Datastore and Firestore are different products. Via Firestore console (https://firebase.corp.google.com/), would you confirm you created documents in Firestore? – suztomo Aug 23 '21 at 13:50
  • For Firestore, you should use com.google.cloud:spring-cloud-gcp-starter-data-firestore:2.0.4. (Notice the groupID difference) 1.2.8.RELEASE is old. – suztomo Aug 23 '21 at 15:46

0 Answers0