Skip to content

Auto Index Creation creates indexes under _default scope #1927

Open
@furkantarikgocmen

Description

@furkantarikgocmen

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(); }
}

Metadata

Metadata

Assignees

Labels

Type

No type

Projects

No projects

Milestone

No milestone

Relationships

None yet

Development

No branches or pull requests

Issue actions