-
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 3 commits
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 |
---|---|---|
|
@@ -32,6 +32,7 @@ | |
import org.elasticsearch.client.RequestOptions; | ||
import org.elasticsearch.client.indices.CreateIndexRequest; | ||
import org.elasticsearch.client.indices.GetIndexRequest; | ||
import org.elasticsearch.client.indices.GetIndexResponse; | ||
import org.elasticsearch.client.indices.GetIndexTemplatesRequest; | ||
import org.elasticsearch.client.indices.GetIndexTemplatesResponse; | ||
import org.elasticsearch.client.indices.GetMappingsRequest; | ||
|
@@ -51,6 +52,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; | ||
|
@@ -60,22 +62,26 @@ | |
* | ||
* @author Peter-Josef Meisch | ||
* @author Sascha Woo | ||
* @author George Popides | ||
* @since 4.0 | ||
*/ | ||
class DefaultIndexOperations extends AbstractDefaultIndexOperations implements IndexOperations { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultIndexOperations.class); | ||
|
||
private final ElasticsearchRestTemplate restTemplate; | ||
private final ResponseConverter responseConverter; | ||
|
||
public DefaultIndexOperations(ElasticsearchRestTemplate restTemplate, Class<?> boundClass) { | ||
super(restTemplate.getElasticsearchConverter(), boundClass); | ||
this.restTemplate = restTemplate; | ||
this.responseConverter = initResponseConverter(restTemplate); | ||
} | ||
|
||
public DefaultIndexOperations(ElasticsearchRestTemplate restTemplate, IndexCoordinates boundIndex) { | ||
super(restTemplate.getElasticsearchConverter(), boundIndex); | ||
this.restTemplate = restTemplate; | ||
this.responseConverter = initResponseConverter(restTemplate); | ||
} | ||
|
||
@Override | ||
|
@@ -256,5 +262,22 @@ public boolean deleteTemplate(DeleteTemplateRequest deleteTemplateRequest) { | |
client -> client.indices().deleteTemplate(deleteIndexTemplateRequest, RequestOptions.DEFAULT).isAcknowledged()); | ||
} | ||
|
||
@Override | ||
public List<IndexInformation> getInformation() { | ||
IndexCoordinates indexCoordinates = getIndexCoordinates(); | ||
GetIndexRequest request = requestFactory.getIndexRequest(indexCoordinates); | ||
|
||
return restTemplate.execute( | ||
client -> { | ||
GetIndexResponse getIndexResponse = client.indices().get(request, RequestOptions.DEFAULT); | ||
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 responseConverter.indexInformationCollection(getIndexResponse); | ||
}); | ||
} | ||
|
||
// endregion | ||
|
||
private ResponseConverter initResponseConverter(ElasticsearchRestTemplate restTemplate) { | ||
return new ResponseConverter(new RequestFactory(restTemplate.getElasticsearchConverter())); | ||
} | ||
|
||
} |
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,24 +69,29 @@ | |
* | ||
* @author Peter-Josef Meisch | ||
* @author Sascha Woo | ||
* @author George Popides | ||
* @since 4.0 | ||
*/ | ||
class DefaultTransportIndexOperations extends AbstractDefaultIndexOperations implements IndexOperations { | ||
|
||
private static final Logger LOGGER = LoggerFactory.getLogger(DefaultTransportIndexOperations.class); | ||
|
||
private final ResponseConverter responseConverter; | ||
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. move to the base class |
||
|
||
private final Client client; | ||
|
||
public DefaultTransportIndexOperations(Client client, ElasticsearchConverter elasticsearchConverter, | ||
Class<?> boundClass) { | ||
super(elasticsearchConverter, boundClass); | ||
this.client = client; | ||
this.responseConverter = initResponseConverter(elasticsearchConverter); | ||
} | ||
|
||
public DefaultTransportIndexOperations(Client client, ElasticsearchConverter elasticsearchConverter, | ||
IndexCoordinates boundIndex) { | ||
super(elasticsearchConverter, boundIndex); | ||
this.client = client; | ||
this.responseConverter = initResponseConverter(elasticsearchConverter); | ||
} | ||
|
||
@Override | ||
|
@@ -296,4 +304,20 @@ 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 getIndexResponse = client.admin().indices().getIndex(getIndexRequest).actionGet(); | ||
|
||
return responseConverter.indexInformationCollection(getIndexResponse); | ||
} | ||
|
||
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 |
||
private ResponseConverter initResponseConverter(ElasticsearchConverter elasticsearchConverter) { | ||
return new ResponseConverter(new RequestFactory(elasticsearchConverter)); | ||
} | ||
} |
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; | ||
|
||
|
@@ -41,6 +42,7 @@ | |
* | ||
* @author Peter-Josef Meisch | ||
* @author Sascha Woo | ||
* @author George Popides | ||
* @since 4.0 | ||
*/ | ||
public interface IndexOperations { | ||
|
@@ -317,5 +319,13 @@ default boolean deleteTemplate(String templateName) { | |
*/ | ||
IndexCoordinates getIndexCoordinates(); | ||
|
||
|
||
/** | ||
* | ||
* @return a list of {@link IndexInformation} | ||
* @since 4.2 | ||
*/ | ||
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 | ||
} |
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.
this can be moved to the parent
AbstractDefaultIndexOperations
and beprotected