Skip to content

Autoindexing fails if index field name contains '.' #1166

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
vals-productions opened this issue Jul 30, 2021 · 1 comment · Fixed by #1169
Closed

Autoindexing fails if index field name contains '.' #1166

vals-productions opened this issue Jul 30, 2021 · 1 comment · Fixed by #1169
Labels
type: bug A general bug

Comments

@vals-productions
Copy link

@Document
@CompositeQueryIndex(name="AnotherEntity_idx", fields = {"anotherEntity.id"})
public class DatabaseEntity  {

private AnotherEntity anotherEntity;
....
}

Index generation will fail with the error:

Could not auto-create index with statement: CREATE INDEX idx_databasentity_anotherentity.id ON .....

note period '.' in index name. Apparently couchbase does not like it.

It probably could either replace '.' with '_' and/or, use index name provided in the annotation?

I can create the index manually through couchbase admin webapp if index name was acceptable.

The code is in CouchbasePersistentEntityIndexResolver createCompositeQueryIndexDefinitions method. As you cen see it appends field name and does not consider annotation index name.

line 133: String indexName = "idx_" + StringUtils.uncapitalize(entity.getType().getSimpleName()) + "_" + fieldsIndexName;
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jul 30, 2021
@mikereiche
Copy link
Collaborator

Needs to replace '.' with '_'.
Line 98 in CouchbasePersistentEntityIndexCreator

	StringBuilder statement = new StringBuilder("CREATE INDEX `").append(indexToCreate.getIndexName().replaceAll(".","_")).append("` ON `")
			.append(couchbaseOperations.getBucketName()).append("` (")
			.append(String.join(",", indexToCreate.getIndexFields())).append(")");

And enclosing in back-ticks gives a better error message for invalid characters.
"msg": "GSI CreateIndex() - cause: Invalid index name",
"query": "CREATE INDEX adv_meta_id.class ON my_bucket(_class)"

@mikereiche mikereiche added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged labels Aug 10, 2021
mikereiche added a commit that referenced this issue Aug 11, 2021
mikereiche added a commit that referenced this issue Aug 11, 2021
mikereiche added a commit that referenced this issue Aug 11, 2021
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.

3 participants