@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); }
private <T> boolean createIndexWithSettings(Class<T> clazz) { if (clazz.isAnnotationPresent(Setting.class)) { String settingPath = clazz.getAnnotation(Setting.class).settingPath(); if (isNotBlank(settingPath)) { String settings = readFileFromClasspath(settingPath); if (isNotBlank(settings)) { return createIndex(getPersistentEntityFor(clazz).getIndexName(), settings); } } else { logger.info("settingPath in @Setting has to be defined. Using default instead."); } } return createIndex( getPersistentEntityFor(clazz).getIndexName(), getDefaultSettings(getPersistentEntityFor(clazz))); }
private boolean isDocument(Class clazz) { return clazz.isAnnotationPresent(Document.class); }