@Override public <T> boolean putMapping(Class<T> clazz) { if (clazz.isAnnotationPresent(Mapping.class)) { String mappingPath = clazz.getAnnotation(Mapping.class).mappingPath(); if (isNotBlank(mappingPath)) { String mappings = readFileFromClasspath(mappingPath); if (isNotBlank(mappings)) { return putMapping(clazz, mappings); } } else { logger.info("mappingPath in @Mapping has to be defined. Building mappings using @Field"); } } ElasticsearchPersistentEntity<T> persistentEntity = getPersistentEntityFor(clazz); XContentBuilder xContentBuilder = null; try { xContentBuilder = buildMapping( clazz, persistentEntity.getIndexType(), persistentEntity.getIdProperty().getFieldName(), persistentEntity.getParentType()); } catch (Exception e) { throw new ElasticsearchException("Failed to build mapping for " + clazz.getSimpleName(), e); } return putMapping(clazz, xContentBuilder); }
private ElasticsearchPersistentEntity getPersistentEntityFor(Class clazz) { Assert.isTrue( clazz.isAnnotationPresent(Document.class), "Unable to identify index name. " + clazz.getSimpleName() + " is not a Document. Make sure the document class is annotated with @Document(indexName=\"foo\")"); return elasticsearchConverter.getMappingContext().getPersistentEntity(clazz); }