DATAES-85 - Add support to get elasticsearch mappings
This commit is contained in:
@@ -69,6 +69,22 @@ public interface ElasticsearchOperations {
|
||||
*/
|
||||
<T> boolean putMapping(Class<T> clazz);
|
||||
|
||||
/**
|
||||
* Get mapping for a class
|
||||
*
|
||||
* @param clazz
|
||||
* @param <T>
|
||||
*/
|
||||
<T> Map getMapping(Class<T> clazz);
|
||||
|
||||
/**
|
||||
* Get mapping for a given indexName and type
|
||||
*
|
||||
* @param indexName
|
||||
* @param type
|
||||
*/
|
||||
Map getMapping(String indexName, String type);
|
||||
|
||||
/**
|
||||
* Get settings for a given indexName
|
||||
*
|
||||
|
||||
@@ -35,6 +35,7 @@ import org.elasticsearch.action.admin.cluster.state.ClusterStateRequest;
|
||||
import org.elasticsearch.action.admin.indices.create.CreateIndexRequestBuilder;
|
||||
import org.elasticsearch.action.admin.indices.delete.DeleteIndexRequest;
|
||||
import org.elasticsearch.action.admin.indices.mapping.delete.DeleteMappingRequest;
|
||||
import org.elasticsearch.action.admin.indices.mapping.get.GetMappingsRequest;
|
||||
import org.elasticsearch.action.admin.indices.mapping.put.PutMappingRequestBuilder;
|
||||
import org.elasticsearch.action.admin.indices.settings.get.GetSettingsRequest;
|
||||
import org.elasticsearch.action.bulk.BulkItemResponse;
|
||||
@@ -150,6 +151,25 @@ public class ElasticsearchTemplate implements ElasticsearchOperations {
|
||||
}
|
||||
}
|
||||
|
||||
@Override
|
||||
public Map getMapping(String indexName, String type) {
|
||||
Assert.notNull(indexName, "No index defined for putMapping()");
|
||||
Assert.notNull(type, "No type defined for putMapping()");
|
||||
Map mappings = null;
|
||||
try {
|
||||
mappings = client.admin().indices().getMappings(new GetMappingsRequest().indices(indexName).types(type))
|
||||
.actionGet().getMappings().get(indexName).get(type).getSourceAsMap();
|
||||
} catch (Exception e) {
|
||||
throw new ElasticsearchException("Error while getting mapping for indexName : " + indexName + " type : " + type + " " + e.getMessage());
|
||||
}
|
||||
return mappings;
|
||||
}
|
||||
|
||||
@Override
|
||||
public <T> Map getMapping(Class<T> clazz) {
|
||||
return getMapping(getPersistentEntityFor(clazz).getIndexName(), getPersistentEntityFor(clazz).getIndexType());
|
||||
}
|
||||
|
||||
@Override
|
||||
public ElasticsearchConverter getElasticsearchConverter() {
|
||||
return elasticsearchConverter;
|
||||
|
||||
Reference in New Issue
Block a user