Skip to content

AutoIndexing is not Working properly [DATACOUCH-550] #858

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

Closed
spring-projects-issues opened this issue May 12, 2020 · 5 comments
Closed

AutoIndexing is not Working properly [DATACOUCH-550] #858

spring-projects-issues opened this issue May 12, 2020 · 5 comments
Assignees
Labels
type: bug A general bug

Comments

@spring-projects-issues
Copy link

deniswsrosa opened DATACOUCH-550 and commented

I have enabled autoindexing according to the docs:

@Configuration
public class Config extends AbstractCouchbaseConfiguration {


 @Override
 public String getConnectionString() {
 return "couchbase://127.0.0.1";
 }

 @Override
 public String getUserName() {
 return "Administrator";
 }

 @Override
 public String getPassword() {
 return "password";
 }

 @Override
 public String getBucketName() {
 return "default";
 }


 /**
 * OPTIONAL: In this example we are using annotations to
 */

 @Override
 protected boolean autoIndexCreation() {
 return true;
 }
}

 

And here is my entity:

 

@Document
@Data
@ToString
@CompositeQueryIndex(fields = {"id", "name", "position"})
public class User {

 @Id
 private String id;
 @QueryIndexed
 private String name;
 @QueryIndexed
 private String position;
 private String description;
 private double accountBalance;
}

 

I have tried many variations of the mapping above, and after the application starts no index is created on the target bucket.

 

 

 

 

 


Affects: 4.0 GA (Neumann)

Referenced from: pull request #295

1 votes, 5 watchers

@spring-projects-issues
Copy link
Author

Michael Reiche commented

AutoIndexing - it works as expected in JUnit tests initialized with @SpringJUnitConfig , but in an spring boot app, when the couchbaseTemplate bean is created, it takes a mappingCouchbaseConverter as the first argument, which in turn takes a couchbaseMappingContext as an argument.  This means that the couchMappingContext is initialized before CouchbaseTemplate.    It is during the initalization of the couchbaseMappingContext that the persistent-entities are processed - including a multicast message to all the applcation listeners.  However, at the time, the auto-indexing application listener has not yet been created by CouchbaseTemplate.  So either there's is something not correct about how the spring-boot application is configured, or the auto-indexing listener needs to be created in couchbaseMappingContext - before the processing of persistent-entities.  (the persistent-entities do get examined when the couchbaseTemplate is created - but they are already cached, so they do not get re-processed. 

@spring-projects-issues
Copy link
Author

Mark Paluch commented

Note that we disabled auto-index creation by default in MongoDB (DATAMONGO-2477) as automatic index creation creates several subsequent issues and desires to customize the behavior.

@spring-projects-issues
Copy link
Author

micopiira commented

*CouchbasePersistentEntityIndexCreator#onApplicationEvent(MappingContextEvent<?, ?>)* seems to never get called even when auto-index is set to true. Using spring-data-couchbase 4.1.2 with Spring Boot.

@spring-projects-issues
Copy link
Author

Michael Reiche commented

Hi micopiira - it will only work in JUnit tests initialized with @SpringJUnitConfig - see my note above. 

And although I've added a pull-request to capture the analysis I did earlier, there still needs to be a discussion if this is something we want to support

@mikereiche
Copy link
Collaborator

Fixed in
03ad369

And that was superseded with
80bae4b

mikereiche added a commit that referenced this issue Feb 18, 2021
The previous "Revert" only reverted CouchbaseTemplate resulting in compilation errors in master.

Closes #858
mikereiche added a commit that referenced this issue Feb 18, 2021
The previous "Revert" only reverted CouchbaseTemplate resulting in compilation errors in master.

Closes #858
daschl pushed a commit that referenced this issue Feb 18, 2021
The previous "Revert" only reverted CouchbaseTemplate resulting in compilation errors in master.

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

Successfully merging a pull request may close this issue.

2 participants