-
Notifications
You must be signed in to change notification settings - Fork 1.3k
Add function to list all indexes #1693
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
Changes from 1 commit
3fbc0c7
3337cd8
84f76dd
5967c77
b4d7bd1
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -18,8 +18,7 @@ | |
import static org.elasticsearch.client.Requests.*; | ||
import static org.springframework.util.StringUtils.*; | ||
|
||
import reactor.core.publisher.Mono; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
|
@@ -38,7 +37,6 @@ | |
import org.slf4j.Logger; | ||
import org.slf4j.LoggerFactory; | ||
import org.springframework.core.annotation.AnnotatedElementUtils; | ||
import org.springframework.core.annotation.AnnotationAttributes; | ||
import org.springframework.dao.InvalidDataAccessApiUsageException; | ||
import org.springframework.data.elasticsearch.NoSuchIndexException; | ||
import org.springframework.data.elasticsearch.annotations.Mapping; | ||
|
@@ -55,11 +53,16 @@ | |
import org.springframework.data.elasticsearch.core.index.TemplateData; | ||
import org.springframework.data.elasticsearch.core.mapping.ElasticsearchPersistentEntity; | ||
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates; | ||
import org.springframework.data.elasticsearch.core.mapping.IndexInformation; | ||
import org.springframework.http.HttpHeaders; | ||
import org.springframework.lang.Nullable; | ||
import org.springframework.util.Assert; | ||
|
||
import reactor.core.publisher.Mono; | ||
|
||
/** | ||
* @author Peter-Josef Meisch | ||
* @author George Popides | ||
* @since 4.1 | ||
*/ | ||
class DefaultReactiveIndexOperations implements ReactiveIndexOperations { | ||
|
@@ -304,6 +307,14 @@ public IndexCoordinates getIndexCoordinates() { | |
return (boundClass != null) ? getIndexCoordinatesFor(boundClass) : boundIndex; | ||
} | ||
|
||
@Override | ||
public Mono<List<IndexInformation>> getInformation() { | ||
org.elasticsearch.client.indices.GetIndexRequest getIndexRequest = requestFactory.getIndexRequest(getIndexCoordinates()); | ||
|
||
return Mono.from(operations.executeWithIndicesClient(client -> client.getIndex(HttpHeaders.EMPTY, getIndexRequest) | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here the mapping should be done from Elasticsearch types to our data |
||
.map(IndexInformation::createList))); | ||
} | ||
|
||
private IndexCoordinates getIndexCoordinatesFor(Class<?> clazz) { | ||
return operations.getElasticsearchConverter().getMappingContext().getRequiredPersistentEntity(clazz) | ||
.getIndexCoordinates(); | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,8 @@ | |
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder; | ||
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest; | ||
import org.elasticsearch.action.admin.indices.exists.indices.IndicesExistsRequest; | ||
import org.elasticsearch.action.admin.indices.get.GetIndexRequest; | ||
import org.elasticsearch.action.admin.indices.get.GetIndexResponse; | ||
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest; | ||
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequestBuilder; | ||
import org.elasticsearch.action.admin.indices.refresh.RefreshRequest; | ||
|
@@ -57,6 +59,7 @@ | |
import org.springframework.data.elasticsearch.core.index.PutTemplateRequest; | ||
import org.springframework.data.elasticsearch.core.index.TemplateData; | ||
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates; | ||
import org.springframework.data.elasticsearch.core.mapping.IndexInformation; | ||
import org.springframework.data.elasticsearch.core.query.AliasQuery; | ||
import org.springframework.lang.Nullable; | ||
import org.springframework.util.Assert; | ||
|
@@ -66,6 +69,7 @@ | |
* | ||
* @author Peter-Josef Meisch | ||
* @author Sascha Woo | ||
* @author George Popides | ||
* @since 4.0 | ||
*/ | ||
class DefaultTransportIndexOperations extends AbstractDefaultIndexOperations implements IndexOperations { | ||
|
@@ -296,4 +300,16 @@ public boolean deleteTemplate(DeleteTemplateRequest deleteTemplateRequest) { | |
deleteTemplateRequest); | ||
return client.admin().indices().deleteTemplate(deleteIndexTemplateRequest).actionGet().isAcknowledged(); | ||
} | ||
|
||
@Override | ||
public List<IndexInformation> getInformation() { | ||
GetIndexRequest getIndexRequest = new GetIndexRequest(); | ||
IndexCoordinates index = getIndexCoordinates(); | ||
|
||
getIndexRequest.indices(index.getIndexNames()); | ||
|
||
GetIndexResponse response = client.admin().indices().getIndex(getIndexRequest).actionGet(); | ||
|
||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. here the mapping should be done from Elasticsearch types to our data |
||
return IndexInformation.createList(response); | ||
} | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -29,6 +29,7 @@ | |
import org.springframework.data.elasticsearch.core.index.PutTemplateRequest; | ||
import org.springframework.data.elasticsearch.core.index.TemplateData; | ||
import org.springframework.data.elasticsearch.core.mapping.IndexCoordinates; | ||
import org.springframework.data.elasticsearch.core.mapping.IndexInformation; | ||
import org.springframework.data.elasticsearch.core.query.AliasQuery; | ||
import org.springframework.lang.Nullable; | ||
|
||
|
@@ -317,5 +318,7 @@ default boolean deleteTemplate(String templateName) { | |
*/ | ||
IndexCoordinates getIndexCoordinates(); | ||
|
||
List<IndexInformation> getInformation(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. please add Javadoc with a |
||
|
||
// endregion | ||
} |
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -15,8 +15,10 @@ | |
*/ | ||
package org.springframework.data.elasticsearch.core; | ||
|
||
import org.springframework.data.elasticsearch.core.mapping.IndexInformation; | ||
import reactor.core.publisher.Mono; | ||
|
||
import java.util.List; | ||
import java.util.Map; | ||
import java.util.Set; | ||
|
||
|
@@ -284,5 +286,6 @@ default Mono<Boolean> deleteTemplate(String templateName) { | |
*/ | ||
IndexCoordinates getIndexCoordinates(); | ||
|
||
Mono<List<IndexInformation>> getInformation(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. we should rather return a |
||
// endregion | ||
} |
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.
here the mapping should be done from Elasticsearch types to our data