try harder to load the default mapping from the class load, and if we fail, just use the default value (which people really never change).

This commit is contained in:
Shay Banon 2012-07-31 00:10:25 +02:00
parent 0a5a068269
commit 68c76e6738
1 changed files with 15 additions and 4 deletions

View File

@ -114,6 +114,9 @@ public class MapperService extends AbstractIndexComponent implements Iterable<Do
} catch (FailedToResolveConfigException e) { } catch (FailedToResolveConfigException e) {
// not there, default to the built in one // not there, default to the built in one
defaultMappingUrl = indexSettings.getClassLoader().getResource("org/elasticsearch/index/mapper/default-mapping.json"); defaultMappingUrl = indexSettings.getClassLoader().getResource("org/elasticsearch/index/mapper/default-mapping.json");
if (defaultMappingUrl == null) {
defaultMappingUrl = MapperService.class.getClassLoader().getResource("org/elasticsearch/index/mapper/default-mapping.json");
}
} }
} else { } else {
try { try {
@ -128,10 +131,18 @@ public class MapperService extends AbstractIndexComponent implements Iterable<Do
} }
} }
try { if (defaultMappingUrl == null) {
defaultMappingSource = Streams.copyToString(new InputStreamReader(defaultMappingUrl.openStream(), Charsets.UTF_8)); logger.info("failed to find default-mapping.json in the classpath, using the default template");
} catch (IOException e) { defaultMappingSource = "{\n" +
throw new MapperException("Failed to load default mapping source from [" + defaultMappingLocation + "]", e); " \"_default_\":{\n" +
" }\n" +
"}";
} else {
try {
defaultMappingSource = Streams.copyToString(new InputStreamReader(defaultMappingUrl.openStream(), Charsets.UTF_8));
} catch (IOException e) {
throw new MapperException("Failed to load default mapping source from [" + defaultMappingLocation + "]", e);
}
} }
logger.debug("using dynamic[{}], default mapping: default_mapping_location[{}], loaded_from[{}] and source[{}]", dynamic, defaultMappingLocation, defaultMappingUrl, defaultMappingSource); logger.debug("using dynamic[{}], default mapping: default_mapping_location[{}], loaded_from[{}] and source[{}]", dynamic, defaultMappingLocation, defaultMappingUrl, defaultMappingSource);