update builtin mappings to work against config/mappings/_default, and also config/mappings/[index_name]

This commit is contained in:
kimchy 2010-04-09 15:04:38 +03:00
parent 7c93c1915f
commit 152aa3553e
1 changed files with 24 additions and 12 deletions

View File

@ -177,20 +177,16 @@ public class MetaDataService extends AbstractComponent {
} }
File mappingsDir = new File(environment.configFile(), "mappings"); File mappingsDir = new File(environment.configFile(), "mappings");
if (mappingsDir.exists() && mappingsDir.isDirectory()) { if (mappingsDir.exists() && mappingsDir.isDirectory()) {
File[] mappingsFiles = mappingsDir.listFiles(); File defaultMappingsDir = new File(mappingsDir, "_default");
for (File mappingFile : mappingsFiles) { if (mappingsDir.exists() && mappingsDir.isDirectory()) {
String fileNameNoSuffix = mappingFile.getName().substring(0, mappingFile.getName().lastIndexOf('.')); addMappings(mappings, defaultMappingsDir);
if (mappings.containsKey(fileNameNoSuffix)) { }
// if we have the mapping defined, ignore it File indexMappingsDir = new File(mappingsDir, index);
continue; if (mappingsDir.exists() && mappingsDir.isDirectory()) {
} addMappings(mappings, indexMappingsDir);
try {
mappings.put(fileNameNoSuffix, Streams.copyToString(new FileReader(mappingFile)));
} catch (IOException e) {
logger.warn("Failed to read mapping [" + fileNameNoSuffix + "] from location [" + mappingFile + "], ignoring...", e);
}
} }
} }
final Map<String, String> fMappings = mappings; final Map<String, String> fMappings = mappings;
final CountDownLatch latch = new CountDownLatch(clusterService.state().nodes().size()); final CountDownLatch latch = new CountDownLatch(clusterService.state().nodes().size());
@ -247,6 +243,22 @@ public class MetaDataService extends AbstractComponent {
return new CreateIndexResult(acknowledged); return new CreateIndexResult(acknowledged);
} }
private void addMappings(Map<String, String> mappings, File mappingsDir) {
File[] mappingsFiles = mappingsDir.listFiles();
for (File mappingFile : mappingsFiles) {
String fileNameNoSuffix = mappingFile.getName().substring(0, mappingFile.getName().lastIndexOf('.'));
if (mappings.containsKey(fileNameNoSuffix)) {
// if we have the mapping defined, ignore it
continue;
}
try {
mappings.put(fileNameNoSuffix, Streams.copyToString(new FileReader(mappingFile)));
} catch (IOException e) {
logger.warn("Failed to read mapping [" + fileNameNoSuffix + "] from location [" + mappingFile + "], ignoring...", e);
}
}
}
public synchronized DeleteIndexResult deleteIndex(final String index, TimeValue timeout) throws IndexMissingException { public synchronized DeleteIndexResult deleteIndex(final String index, TimeValue timeout) throws IndexMissingException {
RoutingTable routingTable = clusterService.state().routingTable(); RoutingTable routingTable = clusterService.state().routingTable();
if (!routingTable.hasIndex(index)) { if (!routingTable.hasIndex(index)) {