Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Auto Index Creation creates indexes under _default scope #1927

Open
furkantarikgocmen opened this issue Mar 26, 2024 · 2 comments
Open

Auto Index Creation creates indexes under _default scope #1927

furkantarikgocmen opened this issue Mar 26, 2024 · 2 comments
Assignees
Labels
type: task A general task

Comments

@furkantarikgocmen
Copy link

Hi, i want to define indexes in my @document entitys, but when ApplicationStartup, spring-data-couchbase creates indexes under myBucket._default, so i cant understand why, when i check spring data couchbase package, when index creating in CouchbasePersistentEntityIndexCreator class, createIndex function generates statement with couchbaseOperations.getBucketName(), i want to create index for collection, what is the best way for to do this ? Maybe a way for change query scope or something like that

Environment:

Java 21, spring-data-couchbase-5.2.1, couchbase capella 7.2.4 - couchbase sandbox 7.0.2 (same for both)

BaseDocument:

@Document
public class BaseDocument implements Serializable {
    @Id
    @GeneratedValue(strategy = GenerationStrategy.UNIQUE)
    protected String id;

    @CreatedDate
    protected Date documentCreationDate;
}

My Entity:

@Getter
@Setter
@NoArgsConstructor
@AllArgsConstructor
@TypeAlias("my-entity")
@Scope("logs")
@Collection("my-entity-logs")
@CompositeQueryIndexes({
        @CompositeQueryIndex(fields = {"fieldA", "updatedAt desc"}),
        @CompositeQueryIndex(fields = {"fieldB", "updatedAt asc"})
})
public class MyEntity extends BaseDocument {

    @QueryIndexed
    @Field
    private Long fieldA;

    @Field
    private String fieldB;

    @Field
    private String fieldC;

    @Field
    private String fieldD;

    @Field
    private Date updatedAt;

    @Field
    private String updatedBy;
}

Repository:

@Repository
public interface MyEntityRepository extends CouchbaseRepository<MyEntity, String>, DynamicProxyable<MyEntityRepository> {
}

Service:

@Service
@RequiredArgsConstructor
public class MyEntityService implements BaseService<MyEntity> {
    private final MyEntityRepository myEntityRepository;

    public void saveAll(List<MyEntity> myEntitys) {
        myEntityRepository.saveAll(myEntitys);
    }
}

Configuration:

@Configuration
@EnableCouchbaseRepositories
@EnableCouchbaseAuditing
@RequiredArgsConstructor
public class CouchbaseConfiguration extends AbstractCouchbaseConfiguration {
    private final CouchbaseProperties couchbaseProperties;

    @Override
    protected void configureEnvironment(final ClusterEnvironment.Builder builder) {
        builder.securityConfig().enableTls(couchbaseProperties.getEnableTls());
        builder.ioConfig().enableDnsSrv(couchbaseProperties.getEnableDnsSrv());
    }

    @Override
    public String getConnectionString() {
        return couchbaseProperties.getConnectionString();
    }

    @Override
    public String getUserName() {
        return couchbaseProperties.getUsername();
    }

    @Override
    public String getPassword() {
        return couchbaseProperties.getPassword();
    }

    @Override
    public String getBucketName() {
        return couchbaseProperties.getBucket();
    }

    @Override
    protected boolean autoIndexCreation() { return couchbaseProperties.getAutoIndexCreation(); }
}
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Mar 26, 2024
@mikereiche
Copy link
Collaborator

i want to create index for collection, what is the best way for to do this ?

The best way? Do this manually outside of spring data. This @QueryIndexed annotation to start indexing on startup is problematic because it can delay startup, and also the application will complete startup before the indexing is complete giving unexpected results. Other spring data technologies that had this have removed it due to such complications.

The reason that it doesn't use the scope and collection is because the annotation was implemented before scopes and collections and not updated. I will investigate to see what is needed to update it for scopes and collections.

@mikereiche mikereiche added type: task A general task and removed status: waiting-for-triage An issue we've not yet triaged labels Mar 27, 2024
@mikereiche mikereiche self-assigned this Mar 27, 2024
@mikereiche
Copy link
Collaborator

I did not get this into the May release. Sorry.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: task A general task
Projects
None yet
Development

No branches or pull requests

3 participants