-
Notifications
You must be signed in to change notification settings - Fork 1.3k
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
Allow IndexCoordinates in repositories #2505
base: main
Are you sure you want to change the base?
Conversation
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Looks good to me, I left some comments, but only minor things.
Needs integration tests, but as you wrote, still a draft.
@@ -32,8 +30,6 @@ | |||
import org.springframework.util.Assert; | |||
import org.springframework.util.ClassUtils; | |||
|
|||
import java.util.Collections; | |||
|
|||
/** | |||
* AbstractElasticsearchRepositoryQuery | |||
* |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add yourself to the authors in all the files you change
|
||
Object result = null; | ||
|
||
if (isDeleteQuery()) { | ||
index = elasticsearchOperations.getIndexCoordinatesFor(clazz); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
don't need this line, index is already set above
*/ | ||
Object[] getValues(); | ||
|
||
IndexCoordinates getIndexCoordinatesOrDefaults(@NonNull IndexCoordinates defaults); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
add javadoc to the new method
class ElasticsearchParameter extends Parameter { | ||
static class ElasticsearchParameter extends Parameter { | ||
|
||
private final boolean indexCoordinatesParameter; |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
private final boolean indexCoordinatesParameter; | |
private final boolean isIndexCoordinatesParameter; |
int index = 0; | ||
List<Integer> foundIndices = new ArrayList<>(); | ||
for (ElasticsearchParameter parameter : this) { | ||
if (parameter.isIndexCoordinatesParameter()) { | ||
foundIndices.add(index); | ||
} | ||
index++; | ||
} | ||
if (foundIndices.size() > 1) { | ||
throw new IllegalArgumentException(this + " can only contain at most one IndexCoordinates parameter."); | ||
} | ||
return foundIndices.isEmpty() ? -1 : foundIndices.get(0); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
alternate way without a list
int indexCoordinatesIndex = -1;
int index = 0;
for (ElasticsearchParameter parameter : this) {
if (parameter.isIndexCoordinatesParameter()) {
if(indexCoordinatesIndex != -1) {
throw new IllegalArgumentException(this + " can only contain at most one IndexCoordinates parameter.");
} else {
indexCoordinatesIndex = index;
}
}
index++;
}
return indexCoordinatesIndex;
@Override | ||
public Object[] getValues() { | ||
return values.toArray(); | ||
} | ||
|
||
@Override | ||
public IndexCoordinates getIndexCoordinatesOrDefaults(@NonNull IndexCoordinates defaults) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
public IndexCoordinates getIndexCoordinatesOrDefaults(@NonNull IndexCoordinates defaults) { | |
public IndexCoordinates getIndexCoordinates(@NonNull IndexCoordinates defaults) { |
I would not put that in the method name in addition to the parameter name
Hi, any progress with this one? I could help with integration tests if needed :) |
@Bartolg sitting in my inbox, contribution of tests would be welcome |
It is common to have multiple indexes with the same document structure. E.g. rolling indices over time and having a wildcard alias. Sometimes one wants to select different IndexCoordinates than specified in `@Document(indexName = "...", ...)`. Also you might want to use the same Repository to do cross cluster searches and for this need to specify the IndexCoordinates. It would therefore be helpful to support IndexCoordinates as an argument to repository methods the same way ScrollPosition, Sort and Pageable are handled. This PR is an attempt to introduce this change. I keep it as draft to get some comments I can add tests to it if we can agree on the change being valid.
It is common to have multiple indexes with the same document structure. E.g. rolling indices over time and having a wildcard alias. Sometimes one wants to select different IndexCoordinates than specified in
@Document(indexName = "...", ...)
. Also you might want to use the same Repository to do cross cluster searches and for this need to specify the IndexCoordinates.It would therefore be helpful to support IndexCoordinates as an argument to repository methods the same way ScrollPosition, Sort and Pageable are handled.
This PR is an attempt to introduce this change. I keep it as draft to get some comments I can add tests to it if we can agree on the change being valid and something the spring-data-elasticsearch sees as useful.
com/spring-projects/spring-data-elasticsearch/issues). Add the issue number to the Closes #issue-number line below
Closes #2506