@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 <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))); }